From: Baolu Lu <baolu.lu@linux.intel.com>
To: "Tian, Kevin" <kevin.tian@intel.com>,
Jacob Pan <jacob.jun.pan@linux.intel.com>,
LKML <linux-kernel@vger.kernel.org>,
"iommu@lists.linux.dev" <iommu@lists.linux.dev>,
Jason Gunthorpe <jgg@nvidia.com>, Joerg Roedel <joro@8bytes.org>,
"dmaengine@vger.kernel.org" <dmaengine@vger.kernel.org>,
"vkoul@kernel.org" <vkoul@kernel.org>
Cc: baolu.lu@linux.intel.com, Robin Murphy <robin.murphy@arm.com>,
Will Deacon <will@kernel.org>,
David Woodhouse <dwmw2@infradead.org>,
"Raj, Ashok" <ashok.raj@intel.com>,
"Liu, Yi L" <yi.l.liu@intel.com>,
"Yu, Fenghua" <fenghua.yu@intel.com>,
"Jiang, Dave" <dave.jiang@intel.com>,
"Luck, Tony" <tony.luck@intel.com>,
"Zanussi, Tom" <tom.zanussi@intel.com>
Subject: Re: [PATCH 1/4] iommu/vt-d: Implement set device pasid op for default domain
Date: Fri, 3 Mar 2023 12:38:21 +0800 [thread overview]
Message-ID: <7f8983c8-b703-4960-67b5-97f4053329db@linux.intel.com> (raw)
In-Reply-To: <BN9PR11MB527634EA1ED5067D1FC0D7C68CB39@BN9PR11MB5276.namprd11.prod.outlook.com>
On 3/3/23 11:02 AM, Tian, Kevin wrote:
>> From: Baolu Lu <baolu.lu@linux.intel.com>
>> Sent: Friday, March 3, 2023 10:49 AM
>>
>> On 3/3/23 10:36 AM, Tian, Kevin wrote:
>>>> From: Baolu Lu <baolu.lu@linux.intel.com>
>>>> Sent: Thursday, March 2, 2023 10:07 PM
>>>>> +
>>>>> + if (!sm_supported(iommu) || !info)
>>>>
>>>> @info has been referenced. !info check makes no sense.
>>>>
>>>> Add pasid_supported(iommu).
>>>>
>>>> Do you need to check whether the domain is compatible for this rid
>>>> pasid?
>>>
>>> what kind of compatibility is concerned here? In concept a pasid
>>> can be attached to any domain if it has been successfully attached
>>> to rid. Probably we can add a check here that RID2PASID must
>>> point to the domain already.
>>
>> "...if it has been successfully attached to rid..."
>>
>> We should not have this assumption in iommu driver's callback. The iommu
>> driver has no (and should not have) knowledge about the history of any
>> domain.
>
> but this is an op for default domain which must have been attached
> to RID2PASID and any compatibility check between this domain and device
> should be passed.
This is an op for DMA, DMA-FQ and UNMANAGED domain. The IOMMU driver
doesn't need to interpret the default domain concept. :-)
>
> We can have another set_pasid for unmanaged which then need similar
> check as prepare_domain_attach_device() does.
From the perspective of the iommu driver, there's no essential
difference between DMA and UNMANAGED domains. So almost all IOMMU
drivers maintain a single set of domain ops for them.
>>
>>>
>>>>
>>>>> + return -ENODEV;
>>>>> +
>>>>> + if (WARN_ON(pasid == PASID_RID2PASID))
>>>>> + return -EINVAL;
>>>>
>>>> Add a call to domain_attach_iommu() here to get a refcount of the
>> domain
>>>> ID. And call domain_detach_iommu() in
>> intel_iommu_remove_dev_pasid().
>>>>
>>>
>>> Is it necessary? iommu core doesn't allow taking ownership
>>> if !xa_empty(&group->pasid_array) so if this pasid attach succeeds
>>> this device cannot be attached to another domain before pasid
>>> detach is done on the current domain.
>>
>> It's not about the pasid, but the domain id.
>>
>> This domain's id will be set to a field of the device's pasid entry. It
>> must get a refcount of that domain id to avoid use after free.
>>
>
> If the domain still has attached device (due to this pasid usage) how could
> domain id be freed?
The Intel IOMMU driver uses a user counter to determine when the domain
id could be freed.
Best regards,
baolu
next prev parent reply other threads:[~2023-03-03 4:39 UTC|newest]
Thread overview: 50+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-03-02 0:59 [PATCH 0/4] Re-enable IDXD kernel workqueue under DMA API Jacob Pan
2023-03-02 0:59 ` [PATCH 1/4] iommu/vt-d: Implement set device pasid op for default domain Jacob Pan
2023-03-02 9:37 ` Tian, Kevin
2023-03-02 19:25 ` Jacob Pan
2023-03-02 14:06 ` Baolu Lu
2023-03-03 2:36 ` Tian, Kevin
2023-03-03 2:48 ` Baolu Lu
2023-03-03 3:02 ` Tian, Kevin
2023-03-03 4:38 ` Baolu Lu [this message]
2023-03-03 5:35 ` Tian, Kevin
2023-03-06 19:04 ` Jacob Pan
2023-03-06 19:02 ` Jason Gunthorpe
2023-03-06 23:45 ` Jacob Pan
2023-03-07 0:45 ` Jacob Pan
2023-03-03 5:38 ` Tian, Kevin
2023-03-03 16:35 ` Jacob Pan
2023-03-05 3:05 ` Baolu Lu
2023-03-06 8:18 ` Tian, Kevin
2023-03-06 18:43 ` Jacob Pan
2023-03-06 18:29 ` Jacob Pan
2023-03-06 12:57 ` Jason Gunthorpe
2023-03-06 17:36 ` Jacob Pan
2023-03-06 17:41 ` Jason Gunthorpe
2023-03-07 2:15 ` Baolu Lu
2023-03-02 0:59 ` [PATCH 2/4] iommu/vt-d: Use non-privileged mode for all PASIDs Jacob Pan
2023-03-02 14:11 ` Baolu Lu
2023-03-03 21:40 ` Jacob Pan
2023-03-02 0:59 ` [PATCH 3/4] iommu/sva: Support reservation of global PASIDs Jacob Pan
2023-03-02 3:06 ` kernel test robot
2023-03-02 3:19 ` kernel test robot
2023-03-02 9:43 ` Tian, Kevin
2023-03-03 21:47 ` Jacob Pan
2023-03-06 13:01 ` Jason Gunthorpe
2023-03-06 17:44 ` Jacob Pan
2023-03-06 17:43 ` Jason Gunthorpe
2023-03-06 17:57 ` Jacob Pan
2023-03-06 18:19 ` Jason Gunthorpe
2023-03-06 18:48 ` Luck, Tony
2023-03-06 19:05 ` Jason Gunthorpe
2023-03-09 17:06 ` Jacob Pan
2023-03-16 7:25 ` Tian, Kevin
2023-03-20 17:22 ` Jason Gunthorpe
2023-03-02 0:59 ` [PATCH 4/4] dmaengine/idxd: Re-enable kernel workqueue under DMA API Jacob Pan
2023-03-02 1:03 ` Dave Jiang
2023-03-02 9:47 ` Tian, Kevin
2023-03-02 12:57 ` Jason Gunthorpe
2023-03-03 21:49 ` Jacob Pan
2023-03-03 22:12 ` Jacob Pan
2023-03-03 1:19 ` Baolu Lu
2023-03-03 21:52 ` Jacob Pan
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=7f8983c8-b703-4960-67b5-97f4053329db@linux.intel.com \
--to=baolu.lu@linux.intel.com \
--cc=ashok.raj@intel.com \
--cc=dave.jiang@intel.com \
--cc=dmaengine@vger.kernel.org \
--cc=dwmw2@infradead.org \
--cc=fenghua.yu@intel.com \
--cc=iommu@lists.linux.dev \
--cc=jacob.jun.pan@linux.intel.com \
--cc=jgg@nvidia.com \
--cc=joro@8bytes.org \
--cc=kevin.tian@intel.com \
--cc=linux-kernel@vger.kernel.org \
--cc=robin.murphy@arm.com \
--cc=tom.zanussi@intel.com \
--cc=tony.luck@intel.com \
--cc=vkoul@kernel.org \
--cc=will@kernel.org \
--cc=yi.l.liu@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
Powered by JetHome