Re: [PATCH 1/1] iommu/vt-d: Fix WARN_ON in iommu probe path
From: Bjorn Helgaas
Date: Wed Nov 18 2026 - 10:49:12 EST
On Wed, Nov 18, 2026 at 03:49:30PM +0800, Baolu Lu wrote:
> On 11/18/2026 2:01 AM, Bjorn Helgaas wrote:
> > [+cc Danny and others because this is related to ongoing work at
> > https://lore.kernel.org/all/20261020181053.2646782-1-digonzal@xxxxxxxxxx/]
> >
> > 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:
>
> info->node is initialized with RB_CLEAR_NODE() before the insertion, and
> the remove helper checks RB_EMPTY_NODE() before erasing. If insertion
> was skipped, removal is a no-op, so this error path does not need
> another state check.
Seems like RB_CLEAR_NODE() and RB_EMPTY_NODE() are lacking
documentation: RB_CLEAR_NODE() isn't used at all by lib/rbtree.c and
Documentation/core-api/rbtree.rst doesn't mention it.
But I agree, this does look safe as-is, though requiring a little
inside knowledge of rbtree internals.
> > > 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.
>
> Agreed. The release path should not re-evaluate pci_ats_supported().
>
> > 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.
>
> Sure. I will address this with a follow-up patch.
Great, thank you!
Bjorn