public inbox for kvm@vger.kernel.org
 help / color / mirror / Atom feed
From: Yi Liu <yi.l.liu@intel.com>
To: Vasant Hegde <vasant.hegde@amd.com>, Jason Gunthorpe <jgg@nvidia.com>
Cc: <joro@8bytes.org>, <kevin.tian@intel.com>,
	<baolu.lu@linux.intel.com>, <will@kernel.org>,
	<alex.williamson@redhat.com>, <eric.auger@redhat.com>,
	<nicolinc@nvidia.com>, <kvm@vger.kernel.org>,
	<chao.p.peng@linux.intel.com>, <iommu@lists.linux.dev>,
	<zhenzhong.duan@intel.com>
Subject: Re: [PATCH v2 1/3] iommu: Add a wrapper for remove_dev_pasid
Date: Tue, 29 Oct 2024 13:20:55 +0800	[thread overview]
Message-ID: <305bc6ba-13c5-4b3a-b3c0-284fc573a3ff@intel.com> (raw)
In-Reply-To: <e937b08c-4648-4f92-8ef6-16c52ecd19fa@amd.com>

On 2024/10/23 19:10, Vasant Hegde wrote:
> Hi Yi,
> 
> 
> On 10/22/2024 6:21 PM, Yi Liu wrote:
>> On 2024/10/21 20:33, Jason Gunthorpe wrote:
>>> On Mon, Oct 21, 2024 at 05:35:38PM +0800, Yi Liu wrote:
>>>> On 2024/10/18 22:39, Jason Gunthorpe wrote:
>>>>> On Thu, Oct 17, 2024 at 10:58:22PM -0700, Yi Liu wrote:
>>>>>> The iommu drivers are on the way to drop the remove_dev_pasid op by
>>>>>> extending the blocked_domain to support PASID. However, this cannot be
>>>>>> done in one shot. So far, the Intel iommu and the ARM SMMUv3 driver have
>>>>>> supported it, while the AMD iommu driver has not yet. During this
>>>>>> transition, the IOMMU core needs to support both ways to destroy the
>>>>>> attachment of device/PASID and domain.
>>>>>
>>>>> Let's just fix AMD?
>>>>
>>>> cool.
>>>
>>> You could probably do better on this and fixup
>>> amd_iommu_remove_dev_pasid() to have the right signature directly,
>>> like the other drivers did
>>
>> It might make sense to move the amd_iommu_remove_dev_pasid() to the
>> drivers/iommu/amd/iommu.c and make it to be the blocked_domain_set_dev_pasid().
> 
> I wanted to keep all PASID code in pasid.c. I'd say for now lets keep it in
> pasid.c only.

ok. If so, we may just let the blocked_domain_set_dev_pasid() call
amd_iommu_remove_dev_pasid().

>>
>>
>> diff --git a/drivers/iommu/amd/amd_iommu.h b/drivers/iommu/amd/amd_iommu.h
>> index b11b014fa82d..55ac1ad10fb3 100644
>> --- a/drivers/iommu/amd/amd_iommu.h
>> +++ b/drivers/iommu/amd/amd_iommu.h
>> @@ -54,8 +54,8 @@ void amd_iommu_domain_free(struct iommu_domain *dom);
>>   int iommu_sva_set_dev_pasid(struct iommu_domain *domain,
>>                   struct device *dev, ioasid_t pasid,
>>                   struct iommu_domain *old);
>> -void amd_iommu_remove_dev_pasid(struct device *dev, ioasid_t pasid,
>> -                struct iommu_domain *domain);
>> +void remove_pdom_dev_pasid(struct protection_domain *pdom,
>> +               struct device *dev, ioasid_t pasid);
>>
>>   /* SVA/PASID */
>>   bool amd_iommu_pasid_supported(void);
>> diff --git a/drivers/iommu/amd/iommu.c b/drivers/iommu/amd/iommu.c
>> index 8364cd6fa47d..f807c4956a75 100644
>> --- a/drivers/iommu/amd/iommu.c
>> +++ b/drivers/iommu/amd/iommu.c
>> @@ -2437,6 +2437,30 @@ static int blocked_domain_attach_device(struct
>> iommu_domain *domain,
>>       return 0;
>>   }
>>
> 
> May be we should add comment here or at least explain it in patch description.
> Otherwise it may create confusion. Something like below
> 
> 
> Remove PASID from old domain and device GCR3 table. No need to attach PASID to
> blocked domain as clearing PASID from GCR3 table will make sure all DMAs for
> that PASID is blocked.

got it.

> 
> 
> 
> 
>> +static int blocked_domain_set_dev_pasid(struct iommu_domain *domain,
>> +                    struct device *dev, ioasid_t pasid,
>> +                    struct iommu_domain *old)
>> +{
>> +    struct protection_domain *pdom = to_pdomain(old);
>> +    unsigned long flags;
>> +
>> +    if (old->type != IOMMU_DOMAIN_SVA)
>> +        return -EINVAL;
>> +
>> +    if (!is_pasid_valid(dev_iommu_priv_get(dev), pasid))
>> +        return 0;
>> +
>> +    pdom = to_pdomain(domain);
> 
> This is redundant as you already set pdom to old domain.

yes.

>> +
>> +    spin_lock_irqsave(&pdom->lock, flags);
>> +
>> +    /* Remove PASID from dev_data_list */
>> +    remove_pdom_dev_pasid(pdom, dev, pasid);
>> +
>> +    spin_unlock_irqrestore(&pdom->lock, flags);
>> +    return 0;
>> +}
>> +
>>   static struct iommu_domain blocked_domain = {
>>       .type = IOMMU_DOMAIN_BLOCKED,
>>       .ops = &(const struct iommu_domain_ops) {
>> diff --git a/drivers/iommu/amd/pasid.c b/drivers/iommu/amd/pasid.c
>> index 8c73a30c2800..c43c7286c872 100644
>> --- a/drivers/iommu/amd/pasid.c
>> +++ b/drivers/iommu/amd/pasid.c
>> @@ -39,8 +39,8 @@ static void remove_dev_pasid(struct pdom_dev_data *pdom_dev_data)
>>   }
>>
>>   /* Clear PASID from device GCR3 table and remove pdom_dev_data from list */
>> -static void remove_pdom_dev_pasid(struct protection_domain *pdom,
>> -                  struct device *dev, ioasid_t pasid)
>> +void remove_pdom_dev_pasid(struct protection_domain *pdom,
>> +               struct device *dev, ioasid_t pasid)
>>   {
>>       struct pdom_dev_data *pdom_dev_data;
>>       struct iommu_dev_data *dev_data = dev_iommu_priv_get(dev);
>> @@ -145,25 +145,6 @@ int iommu_sva_set_dev_pasid(struct iommu_domain *domain,
>>       return ret;
>>   }
>>
>> -void amd_iommu_remove_dev_pasid(struct device *dev, ioasid_t pasid,
>> -                struct iommu_domain *domain)
>> -{
>> -    struct protection_domain *sva_pdom;
>> -    unsigned long flags;
>> -
>> -    if (!is_pasid_valid(dev_iommu_priv_get(dev), pasid))
>> -        return;
>> -
>> -    sva_pdom = to_pdomain(domain);
>> -
>> -    spin_lock_irqsave(&sva_pdom->lock, flags);
>> -
>> -    /* Remove PASID from dev_data_list */
>> -    remove_pdom_dev_pasid(sva_pdom, dev, pasid);
>> -
>> -    spin_unlock_irqrestore(&sva_pdom->lock, flags);
>> -}
>> -
>>   static void iommu_sva_domain_free(struct iommu_domain *domain)
>>   {
>>       struct protection_domain *sva_pdom = to_pdomain(domain);
>>
>>

-- 
Regards,
Yi Liu

  reply	other threads:[~2024-10-29  5:16 UTC|newest]

Thread overview: 16+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-10-18  5:58 [PATCH v2 0/3] Support attaching PASID to the blocked_domain Yi Liu
2024-10-18  5:58 ` [PATCH v2 1/3] iommu: Add a wrapper for remove_dev_pasid Yi Liu
2024-10-18 14:39   ` Jason Gunthorpe
2024-10-21  9:35     ` Yi Liu
2024-10-21 12:33       ` Jason Gunthorpe
2024-10-22 12:51         ` Yi Liu
2024-10-23 11:10           ` Vasant Hegde
2024-10-29  5:20             ` Yi Liu [this message]
2024-10-29 16:38               ` Vasant Hegde
2024-10-18  5:58 ` [PATCH v2 2/3] iommu/arm-smmu-v3: Make the blocked domain support PASID Yi Liu
2024-10-22  6:06   ` Nicolin Chen
2024-10-18  5:58 ` [PATCH v2 3/3] iommu/vt-d: " Yi Liu
2024-10-18 15:54   ` Jason Gunthorpe
2024-10-21  9:36     ` Yi Liu
2024-10-22  9:44 ` [PATCH v2 0/3] Support attaching PASID to the blocked_domain Vasant Hegde
2024-10-22 10:14   ` 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=305bc6ba-13c5-4b3a-b3c0-284fc573a3ff@intel.com \
    --to=yi.l.liu@intel.com \
    --cc=alex.williamson@redhat.com \
    --cc=baolu.lu@linux.intel.com \
    --cc=chao.p.peng@linux.intel.com \
    --cc=eric.auger@redhat.com \
    --cc=iommu@lists.linux.dev \
    --cc=jgg@nvidia.com \
    --cc=joro@8bytes.org \
    --cc=kevin.tian@intel.com \
    --cc=kvm@vger.kernel.org \
    --cc=nicolinc@nvidia.com \
    --cc=vasant.hegde@amd.com \
    --cc=will@kernel.org \
    --cc=zhenzhong.duan@intel.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