mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Bjorn Helgaas <helgaas@kernel.org>
To: Lu Baolu <baolu.lu@linux.intel.com>
Cc: iommu@lists.linux.dev, Kevin Tian <kevin.tian@intel.com>,
	Joerg Roedel <joro@8bytes.org>, Will Deacon <will@kernel.org>,
	Robin Murphy <robin.murphy@arm.com>,
	Danny Gonzalez <digonzal@google.com>,
	David Decotigny <decot@google.com>,
	Sheena Mohan <sheenamo@google.com>,
	Jason Gunthorpe <jgg@nvidia.com>,
	Pranjal Shrivastava <praan@google.com>,
	Nicolin Chen <nicolinc@nvidia.com>,
	linux-pci@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: Re: [PATCH 1/1] iommu/vt-d: Fix WARN_ON in iommu probe path
Date: Tue, 17 Nov 2026 12:01:22 -0600	[thread overview]
Message-ID: <20261117180122.GA427856@bhelgaas> (raw)
In-Reply-To: <20240407011429.136282-1-baolu.lu@linux.intel.com>

[+cc Danny and others because this is related to ongoing work at
https://lore.kernel.org/all/20261020181053.2646782-1-digonzal@google.com/]

On Sun, Apr 07, 2024 at 09:14:29AM +0800, Lu Baolu wrote:
> Commit 1a75cc710b95 ("iommu/vt-d: Use rbtree to track iommu probed
> devices") adds all devices probed by the iommu driver in a rbtree
> indexed by the source ID of each device. It assumes that each device
> has a unique source ID. This assumption is incorrect and the VT-d
> spec doesn't state this requirement either.
> ...

> +++ b/drivers/iommu/intel/iommu.c
> @@ -4299,9 +4299,11 @@ static struct iommu_device *intel_iommu_probe_device(struct device *dev)
>       }
>  
>       dev_iommu_priv_set(dev, info);
> -     ret = device_rbtree_insert(iommu, info);
> -     if (ret)
> -             goto free;
> +     if (pdev && pci_ats_supported(pdev)) {
> +             ret = device_rbtree_insert(iommu, info);
> +             if (ret)
> +                     goto free;
> +     }

This change is upstream as 89436f4f5412 ("iommu/vt-d: Fix WARN_ON in
iommu probe path"), but I think there's a problem here.  Previously
the rbtree insertion was unconditional, so the unconditional remove in
the error path was correct.

After 89436f4f5412, the rbtree insertion is conditional.  If
intel_pasid_alloc_table() fails, we try to remove it even though it
may never have been inserted:

>       if (sm_supported(iommu) && !dev_is_real_dma_subdevice(dev)) {
>               ret = intel_pasid_alloc_table(dev);
                if (ret) {
                        dev_err(dev, "PASID table allocation failed\n");
                        goto clear_rbtree;
                }
    ...
    clear_rbtree:
        device_rbtree_remove(info);
    free:
        kfree(info);

> @@ -4336,7 +4338,8 @@ static void intel_iommu_release_device(struct device *dev)
>       struct intel_iommu *iommu = info->iommu;
>  
>       mutex_lock(&iommu->iopf_lock);
> -     device_rbtree_remove(info);
> +     if (dev_is_pci(dev) && pci_ats_supported(to_pci_dev(dev)))
> +             device_rbtree_remove(info);

This is also somewhat problematic because it relies on the assumption
that pci_ats_supported(X) always returns the same value it returned in
intel_iommu_probe_device().  That may be true today, but I don't think
you should rely on it.

I think both issues could be solved if intel/iommu.c kept track of the
rbtree insertion itself, e.g., with a bit in struct
device_domain_info.

>       mutex_unlock(&iommu->iopf_lock);
>  
>       if (sm_supported(iommu) && !dev_is_real_dma_subdevice(dev) &&
> -- 
> 2.34.1
> 

      parent reply	other threads:[~2026-11-17 18:01 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-04-07  1:14 Lu Baolu
2024-04-08  3:52 ` Tian, Kevin
2024-04-08  7:15   ` Baolu Lu
2024-04-08  9:12     ` Tian, Kevin
2024-04-11 12:29   ` Ethan Zhao
2024-04-11  2:47 ` Baolu Lu
2024-04-11  6:53   ` Tian, Kevin
2026-11-17 18:01 ` Bjorn Helgaas [this message]

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=20261117180122.GA427856@bhelgaas \
    --to=helgaas@kernel.org \
    --cc=baolu.lu@linux.intel.com \
    --cc=decot@google.com \
    --cc=digonzal@google.com \
    --cc=iommu@lists.linux.dev \
    --cc=jgg@nvidia.com \
    --cc=joro@8bytes.org \
    --cc=kevin.tian@intel.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-pci@vger.kernel.org \
    --cc=nicolinc@nvidia.com \
    --cc=praan@google.com \
    --cc=robin.murphy@arm.com \
    --cc=sheenamo@google.com \
    --cc=will@kernel.org \
    /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

all inboxes | Powered by JetHome®