Linux-ARM-Kernel Archive on lore.kernel.org
 help / color / mirror / Atom feed
From: Will Deacon <will@kernel.org>
To: Qinxin Xia <xiaqinxin@huawei.com>
Cc: robin.murphy@arm.com, linux-kernel@vger.kernel.org,
	linux-arm-kernel@lists.infradead.org, iommu@lists.linux.dev,
	yangyicong@huawei.com, wangzhou1@hisilicon.com,
	prime.zeng@hisilicon.com, xuwei5@huawei.com,
	fanghao11@huawei.com, jonathan.cameron@huawei.com,
	linuxarm@huawei.com
Subject: Re: [PATCH 1/2] iommu/debug: Add IOMMU page table dump debug facility
Date: Thu, 11 Sep 2025 15:58:22 +0100	[thread overview]
Message-ID: <aMLjjl4nsBuQML3Y@willie-the-truck> (raw)
In-Reply-To: <534119b8-8221-4991-b308-05e8d5918aca@huawei.com>

On Wed, Sep 10, 2025 at 10:58:09AM +0800, Qinxin Xia wrote:
> 
> 
> On 2025/9/9 21:06:33, Will Deacon <will@kernel.org> wrote:
> > On Thu, Aug 14, 2025 at 05:30:04PM +0800, Qinxin Xia wrote:
> > > +/**
> > > + * iova_info_dump - dump iova alloced
> > > + * @s - file structure used to generate serialized output
> > > + * @iovad: - iova domain in question.
> > > + */
> > > +static int iommu_iova_info_dump(struct seq_file *s, struct iommu_domain *domain)
> > > +{
> > > +	struct iova_domain *iovad;
> > > +	unsigned long long pfn;
> > > +	unsigned long i_shift;
> > > +	struct rb_node *node;
> > > +	unsigned long flags;
> > > +	size_t prot_size;
> > > +
> > > +	iovad = iommu_domain_to_iovad(domain);
> > > +	if (!iovad)
> > > +		return -ENOMEM;
> > > +
> > > +	i_shift = iova_shift(iovad);
> > > +
> > > +	/* Take the lock so that no other thread is manipulating the rbtree */
> > > +	spin_lock_irqsave(&iovad->iova_rbtree_lock, flags);
> > > +	assert_spin_locked(&iovad->iova_rbtree_lock);
> > > +
> > > +	for (node = rb_first(&iovad->rbroot); node; node = rb_next(node)) {
> > > +		struct iova *iova = rb_entry(node, struct iova, node);
> > > +
> > > +		if (iova->pfn_hi <= iova->pfn_lo)
> > > +			continue;
> > > +
> > > +		for (pfn = iova->pfn_lo; pfn <= iova->pfn_hi; ) {
> > > +			prot_size = domain->ops->dump_iova_prot(s, domain, pfn << i_shift);
> > > +			pfn = ((pfn << i_shift) + prot_size) >> i_shift;
> > > +		}
> > > +	}
> > > +
> > > +	spin_unlock_irqrestore(&iovad->iova_rbtree_lock, flags);
> > 
> > Why is the IOVA rbtree lock sufficient for serialising the page-table
> > accesses made by ->dump_iova_prot()? I don't see anything here that
> > prevents the walker walking into page-table pages that are e.g. being
> > freed or manipulated concurrently.
> > 
>  Thank you for catching this critical race condition.I will fix this in
>  next version. And,Jason suggests putting io_ptdump on top of iommu pt.
>  What do you think?

I guess it depends on whether or not you want to tie this debug feature
to drivers that support the new page-table stuff.

Will


  reply	other threads:[~2025-09-11 14:58 UTC|newest]

Thread overview: 15+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-08-14  9:30 [PATCH 0/2] iommu: Add io_ptdump debug interface for iommu Qinxin Xia
2025-08-14  9:30 ` [PATCH 1/2] iommu/debug: Add IOMMU page table dump debug facility Qinxin Xia
2025-08-15  6:47   ` kernel test robot
2025-08-15  9:57   ` kernel test robot
2025-09-09 13:06   ` Will Deacon
2025-09-10  2:58     ` Qinxin Xia
2025-09-11 14:58       ` Will Deacon [this message]
2025-08-14  9:30 ` [PATCH 2/2] iommu/io-pgtable: Add ARM SMMUv3 page table dump support Qinxin Xia
2025-08-15  9:14   ` kernel test robot
2025-09-02 16:10 ` [PATCH 0/2] iommu: Add io_ptdump debug interface for iommu Jason Gunthorpe
2025-09-10  3:20   ` Qinxin Xia
2025-09-10 14:15     ` Jason Gunthorpe
2025-09-11 14:08       ` Qinxin Xia
2025-09-15 16:28         ` Jason Gunthorpe
2025-10-18 10:39           ` Qinxin Xia

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=aMLjjl4nsBuQML3Y@willie-the-truck \
    --to=will@kernel.org \
    --cc=fanghao11@huawei.com \
    --cc=iommu@lists.linux.dev \
    --cc=jonathan.cameron@huawei.com \
    --cc=linux-arm-kernel@lists.infradead.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linuxarm@huawei.com \
    --cc=prime.zeng@hisilicon.com \
    --cc=robin.murphy@arm.com \
    --cc=wangzhou1@hisilicon.com \
    --cc=xiaqinxin@huawei.com \
    --cc=xuwei5@huawei.com \
    --cc=yangyicong@huawei.com \
    /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