Linux IOMMU Development
 help / color / mirror / Atom feed
From: Yi Liu <yi.l.liu@intel.com>
To: "Tian, Kevin" <kevin.tian@intel.com>,
	"joro@8bytes.org" <joro@8bytes.org>,
	"baolu.lu@linux.intel.com" <baolu.lu@linux.intel.com>,
	"jgg@nvidia.com" <jgg@nvidia.com>
Cc: "iommu@lists.linux.dev" <iommu@lists.linux.dev>,
	"robin.murphy@arm.com" <robin.murphy@arm.com>,
	"nicolinc@nvidia.com" <nicolinc@nvidia.com>,
	"will@kernel.org" <will@kernel.org>,
	"vasant.hegde@amd.com" <vasant.hegde@amd.com>
Subject: Re: [PATCH v7 02/13] iommu: Introduce a replace API for device pasid
Date: Tue, 25 Feb 2025 19:35:16 +0800	[thread overview]
Message-ID: <5f4bb0b8-0fb2-4db2-a81e-8b093377abd4@intel.com> (raw)
In-Reply-To: <BN9PR11MB527698FB8038D4A41A4191E88CC32@BN9PR11MB5276.namprd11.prod.outlook.com>

On 2025/2/25 17:55, Tian, Kevin wrote:
>> From: Liu, Yi L <yi.l.liu@intel.com>
>> Sent: Sunday, February 16, 2025 11:52 AM
>>
>> -struct iommu_domain *iommu_group_domain(struct iommu_group *group)
>> +static struct iommu_domain *pasid_entry_to_domain(void *pasid_entry)
>>   {
>>   	struct iommu_domain *domain;
>> -	void *pasid_entry;
>> -
>> -	lockdep_assert_held(&group->mutex);
>>
>> -	pasid_entry = xa_load(&group->pasid_array, IOMMU_NO_PASID);
>>   	if (xa_pointer_tag(pasid_entry) == IOMMU_PASID_ARRAY_HANDLE) {
>>   		struct iommu_attach_handle *handle;
>>
> 
> What about calling it iommu_group_pasid_domain(group, pasid)
> which accepts a pasid as parameter so the caller doesn't need to
> do its own xa_load?

I would consider it in the new version. However, if the caller still
has the entry, I may still need this helper to avoid duplicated
xa_load().

>> @@ -3388,7 +3392,20 @@ static int __iommu_set_group_pasid(struct
>> iommu_domain *domain,
>>   	for_each_group_device(group, device) {
>>   		if (device == last_gdev)
>>   			break;
>> -		iommu_remove_dev_pasid(device->dev, pasid, domain);
>> +		/* If no old domain, undo the succeeded devices/pasid */
>> +		if (!old) {
>> +			iommu_remove_dev_pasid(device->dev, pasid,
>> domain);
>> +			continue;
>> +		}
>> +
>> +		/*
>> +		 * Rollback the succeeded devices/pasid to the old domain.
>> +		 * And it is a driver bug to fail attaching with a previously
>> +		 * good domain.
>> +		 */
>> +		if (WARN_ON(old->ops->set_dev_pasid(old, device->dev,
>> +						    pasid, domain)))
>> +			iommu_remove_dev_pasid(device->dev, pasid,
>> domain);
> 
> Above can be simplified as:
> 
> 	if (!old || WARN_ON(old...))
> 		iommu_remove_dev_pasid();

yes.

> 
>> +/**
>> + * iommu_replace_device_pasid_handle - Replace the domain that a pasid
>> + *                                     is attached to
>> + * @domain: the new iommu domain
>> + * @dev: the attached device.
>> + * @pasid: the pasid of the device.
>> + * @handle: the attach handle.
>> + *
>> + * This API allows the pasid to switch domains. The @pasid should have
>> been
>> + * attached via iommu_replace_device_pasid_handle(), otherwise, this
> 
> why do we care how the pasid has been attached? and in reality people
> does attach, replace, replace, etc, i.e. you cannot expect the 1st operation
> as a replace.

it's a typo. :) It should have been iommu_attach_device_pasid_handle().
However, this comment should be dropped anyhow since we are going to
support replacing domain with handle per the handle series. I'll have
it in a refreshed version of this series.

The replace path is going to have something like the below. If both domain
and handle is the same, it shall return directly.

	pasid_entry = iommu_make_pasid_entry(new_domain, handle);
	curr = xa_cmpxchg(&group->pasid_array, IOMMU_NO_PASID, NULL,
			  XA_ZERO_ENTRY, GFP_KERNEL);
	if (xa_is_err(curr))
		return xa_err(curr);
	if (curr == pasid_entry &&
	    new_domain == pasid_entry_to_domain(curr))
		return 0;


[1] https://lore.kernel.org/linux-iommu/20250218195756.GG4183890@nvidia.com/

-- 
Regards,
Yi Liu

  reply	other threads:[~2025-02-25 11:30 UTC|newest]

Thread overview: 17+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-02-16  3:52 [PATCH v7 00/13] iommufd support pasid attach/replace Yi Liu
2025-02-16  3:52 ` [PATCH v7 01/13] iommu: Add iommu_attach_device_pasid_handle() Yi Liu
2025-02-25  9:47   ` Tian, Kevin
2025-02-16  3:52 ` [PATCH v7 02/13] iommu: Introduce a replace API for device pasid Yi Liu
2025-02-25  9:55   ` Tian, Kevin
2025-02-25 11:35     ` Yi Liu [this message]
2025-02-16  3:52 ` [PATCH v7 03/13] iommufd: Pass @pasid through the device attach/replace path Yi Liu
2025-02-16  3:52 ` [PATCH v7 04/13] iommufd/device: Only add reserved_iova in non-pasid path Yi Liu
2025-02-16  3:52 ` [PATCH v7 05/13] iommufd: Mark PASID-compatible domain Yi Liu
2025-02-16  3:52 ` [PATCH v7 06/13] iommufd: Support pasid attach/replace Yi Liu
2025-02-16  3:52 ` [PATCH v7 07/13] iommufd: Enforce PASID-compatible domain for RID Yi Liu
2025-02-16  3:52 ` [PATCH v7 08/13] iommu/vt-d: Add IOMMU_HWPT_ALLOC_PASID support Yi Liu
2025-02-16  3:52 ` [PATCH v7 09/13] iommufd: Allow allocating PASID-compatible domain Yi Liu
2025-02-16  3:52 ` [PATCH v7 10/13] iommufd/selftest: Add set_dev_pasid in mock iommu Yi Liu
2025-02-16  3:52 ` [PATCH v7 11/13] iommufd/selftest: Add a helper to get test device Yi Liu
2025-02-16  3:52 ` [PATCH v7 12/13] iommufd/selftest: Add test ops to test pasid attach/detach Yi Liu
2025-02-16  3:52 ` [PATCH v7 13/13] iommufd/selftest: Add coverage for iommufd " Yi 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=5f4bb0b8-0fb2-4db2-a81e-8b093377abd4@intel.com \
    --to=yi.l.liu@intel.com \
    --cc=baolu.lu@linux.intel.com \
    --cc=iommu@lists.linux.dev \
    --cc=jgg@nvidia.com \
    --cc=joro@8bytes.org \
    --cc=kevin.tian@intel.com \
    --cc=nicolinc@nvidia.com \
    --cc=robin.murphy@arm.com \
    --cc=vasant.hegde@amd.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