Linux PCI subsystem development
 help / color / mirror / Atom feed
From: Pranjal Shrivastava <praan@google.com>
To: Baolu Lu <baolu.lu@linux.intel.com>
Cc: sashiko-reviews@lists.linux.dev, linux-pci@vger.kernel.org
Subject: Re: [PATCH v4 4/5] iommu/vt-d: Fail probe on ATS configuration failure
Date: Thu, 28 May 2026 17:36:57 +0000	[thread overview]
Message-ID: <ahh9ORDm6EcQ7aKS@google.com> (raw)
In-Reply-To: <17ab0d76-6df7-48f6-a7fd-387934f95c0f@linux.intel.com>

On Thu, May 28, 2026 at 01:19:13PM +0800, Baolu Lu wrote:
> On 5/26/26 04:56, sashiko-bot@kernel.org wrote:
> > > @@ -3288,7 +3294,10 @@ static struct iommu_device *intel_iommu_probe_device(struct device *dev)
> > >   	dev_iommu_priv_set(dev, info);
> > >   	if (pdev && pci_ats_supported(pdev)) {
> > > -		pci_prepare_ats(pdev, VTD_PAGE_SHIFT);
> > > +		ret = pci_prepare_ats(pdev, VTD_PAGE_SHIFT);
> > > +		if (ret)
> > > +			goto free;
> > > +
> > >   		ret = device_rbtree_insert(iommu, info);
> > >   		if (ret)
> > >   			goto free;
> > [Severity: High]
> > This is a pre-existing issue, but does unconditional removal of the rb-node
> > on the error path cause tree corruption for non-ats devices?
> > 
> > If a device does not support ats, the info structure skips the
> > device_rbtree_insert() call here, leaving info->node zero-initialized.
> > 
> > However, if a subsequent operation like intel_pasid_alloc_table() fails,
> > the error path jumps to clear_rbtree:
> > 
> > intel_iommu_probe_device()
> >      ...
> >      clear_rbtree:
> >              device_rbtree_remove(info);
> >      free:
> >              kfree(info);
> > 
> > Calling device_rbtree_remove() on this zero-initialized node causes the
> > rb-tree logic to treat it as a root node with no parent, ultimately
> > overwriting the actual tree root with null and corrupting the device_rbtree.
> 
> Perhaps we can fix it like this?
> 
> diff --git a/drivers/iommu/intel/iommu.c b/drivers/iommu/intel/iommu.c
> index 4d0e65bc131d..849d06dfe1ae 100644
> --- a/drivers/iommu/intel/iommu.c
> +++ b/drivers/iommu/intel/iommu.c
> @@ -157,7 +157,10 @@ static void device_rbtree_remove(struct
> device_domain_info *info)
>         unsigned long flags;
> 
>         spin_lock_irqsave(&iommu->device_rbtree_lock, flags);
> -       rb_erase(&info->node, &iommu->device_rbtree);
> +       if (!RB_EMPTY_NODE(&info->node)) {
> +               rb_erase(&info->node, &iommu->device_rbtree);
> +               RB_CLEAR_NODE(&info->node);
> +       }
>         spin_unlock_irqrestore(&iommu->device_rbtree_lock, flags);
>  }
> 
> @@ -3254,6 +3257,7 @@ static struct iommu_device
> *intel_iommu_probe_device(struct device *dev)
> 
>         info->dev = dev;
>         info->iommu = iommu;
> +       RB_CLEAR_NODE(&info->node);
>         if (dev_is_pci(dev)) {
>                 if (ecap_dev_iotlb_support(iommu->ecap) &&
>                     pci_ats_supported(pdev) &&

Ack. Yes. I'll add it to the next version.

Thanks,
Praan

  reply	other threads:[~2026-05-28 17:37 UTC|newest]

Thread overview: 17+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-05-25 18:43 [PATCH v4 0/5] iommu: Standardize ATS robustness and state tracking Pranjal Shrivastava
2026-05-25 18:43 ` [PATCH v4 1/5] PCI/ATS: Ensure pci_ats_supported() is PF-aware for VFs Pranjal Shrivastava
2026-05-25 19:42   ` Nicolin Chen
2026-05-25 18:43 ` [PATCH v4 2/5] PCI/ATS: Validate STU for VFs in pci_prepare_ats() Pranjal Shrivastava
2026-05-25 19:46   ` Nicolin Chen
2026-05-28 20:27     ` Pranjal Shrivastava
2026-05-25 18:43 ` [PATCH v4 3/5] iommu/arm-smmu-v3: Fix ATS state tracking Pranjal Shrivastava
2026-05-25 20:05   ` Nicolin Chen
2026-05-25 20:30     ` Pranjal Shrivastava
2026-05-25 20:40       ` Nicolin Chen
2026-05-25 20:24   ` sashiko-bot
2026-05-25 18:43 ` [PATCH v4 4/5] iommu/vt-d: Fail probe on ATS configuration failure Pranjal Shrivastava
2026-05-25 20:56   ` sashiko-bot
2026-05-28  5:19     ` Baolu Lu
2026-05-28 17:36       ` Pranjal Shrivastava [this message]
2026-05-25 18:43 ` [PATCH v4 5/5] iommu/amd: " Pranjal Shrivastava
2026-05-25 21:35   ` sashiko-bot

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=ahh9ORDm6EcQ7aKS@google.com \
    --to=praan@google.com \
    --cc=baolu.lu@linux.intel.com \
    --cc=linux-pci@vger.kernel.org \
    --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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox