Linux IOMMU Development
 help / color / mirror / Atom feed
From: Jason Gunthorpe <jgg@ziepe.ca>
To: Guixin Liu <kanie@linux.alibaba.com>
Cc: Joerg Roedel <joro@8bytes.org>, Will Deacon <will@kernel.org>,
	Robin Murphy <robin.murphy@arm.com>,
	Kevin Tian <kevin.tian@intel.com>,
	iommu@lists.linux.dev
Subject: Re: [PATCH v3] iommu: Fix iommu selftest running test mock domain fail
Date: Wed, 24 Sep 2025 09:53:52 -0300	[thread overview]
Message-ID: <20250924125352.GI2547959@ziepe.ca> (raw)
In-Reply-To: <20250924074359.41510-1-kanie@linux.alibaba.com>

On Wed, Sep 24, 2025 at 03:43:59PM +0800, Guixin Liu wrote:
> @@ -1077,6 +1077,7 @@ static void mock_dev_release(struct device *dev)
>  {
>  	struct mock_dev *mdev = to_mock_dev(dev);
>  
> +	iommu_mock_device_abort(&mdev->dev);
>  	ida_free(&mock_dev_ida, mdev->id);
>  	kfree(mdev);
>  }

I don't think this call is necessary? Once device_add() completes the
iommu_bus_notifier() should be active for the device.

BUS_NOTIFY_REMOVED_DEVICE triggers iommu_release_device() which does
dev_iommu_free() and frees the fwspec automatically.

The only unnatural condition is if device_add() fails then the
notifier can't run and the caller has to clean it up.

Yes?

> @@ -1126,6 +1127,10 @@ static struct mock_dev *mock_dev_create(unsigned long dev_flags)
>  		goto err_put;
>  	}
>  
> +	rc = iommu_mock_device_init(&mdev->dev, &mock_iommu.iommu_dev);
> +	if (rc)
> +		goto err_put;
> +
>  	rc = device_add(&mdev->dev);
>  	if (rc)
>  		goto err_put;

So I will suggest one further refinement to pull the device_add() into
iommu_mock_device_add() and then it can internally free the fwspec on
error and don't bother with iommu_mock_device_abort().

But other than that little note this looks fine to me.

Jason

  reply	other threads:[~2025-09-24 12:53 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-09-24  7:43 [PATCH v3] iommu: Fix iommu selftest running test mock domain fail Guixin Liu
2025-09-24 12:53 ` Jason Gunthorpe [this message]
2025-09-25  2:29   ` Guixin Liu

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=20250924125352.GI2547959@ziepe.ca \
    --to=jgg@ziepe.ca \
    --cc=iommu@lists.linux.dev \
    --cc=joro@8bytes.org \
    --cc=kanie@linux.alibaba.com \
    --cc=kevin.tian@intel.com \
    --cc=robin.murphy@arm.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