[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <79c41aab-ec9c-3f5e-65d1-ff857f57816e@linux.intel.com>
Date: Fri, 10 Jun 2022 17:07:10 +0800
From: Baolu Lu <baolu.lu@...ux.intel.com>
To: "Tian, Kevin" <kevin.tian@...el.com>,
"Raj, Ashok" <ashok.raj@...el.com>
Cc: baolu.lu@...ux.intel.com, Joerg Roedel <joro@...tes.org>,
Jason Gunthorpe <jgg@...dia.com>,
Christoph Hellwig <hch@...radead.org>,
Will Deacon <will@...nel.org>,
Robin Murphy <robin.murphy@....com>,
Jean-Philippe Brucker <jean-philippe@...aro.com>,
"Jiang, Dave" <dave.jiang@...el.com>,
Vinod Koul <vkoul@...nel.org>,
Eric Auger <eric.auger@...hat.com>,
"Liu, Yi L" <yi.l.liu@...el.com>,
"Pan, Jacob jun" <jacob.jun.pan@...el.com>,
"iommu@...ts.linux-foundation.org" <iommu@...ts.linux-foundation.org>,
"linux-kernel@...r.kernel.org" <linux-kernel@...r.kernel.org>
Subject: Re: [PATCH v8 02/11] iommu: Add max_pasids field in struct dev_iommu
On 2022/6/10 17:01, Tian, Kevin wrote:
>> From: Baolu Lu <baolu.lu@...ux.intel.com>
>> Sent: Friday, June 10, 2022 2:47 PM
>>
>> On 2022/6/10 03:01, Raj, Ashok wrote:
>>> On Tue, Jun 07, 2022 at 09:49:33AM +0800, Lu Baolu wrote:
>>>> @@ -218,6 +219,30 @@ static void dev_iommu_free(struct device *dev)
>>>> kfree(param);
>>>> }
>>>>
>>>> +static u32 dev_iommu_get_max_pasids(struct device *dev)
>>>> +{
>>>> + u32 max_pasids = dev->iommu->iommu_dev->max_pasids;
>>>> + u32 num_bits;
>>>> + int ret;
>>>> +
>>>> + if (!max_pasids)
>>>> + return 0;
>>>> +
>>>> + if (dev_is_pci(dev)) {
>>>> + ret = pci_max_pasids(to_pci_dev(dev));
>>>> + if (ret < 0)
>>>> + return 0;
>>>> +
>>>> + return min_t(u32, max_pasids, ret);
>>>
>>> Ah.. that answers my other question to consider device pasid-max. I guess
>>> if we need any enforcement of restricting devices that aren't supporting
>>> the full PASID, that will be done by some higher layer?
>>
>> The mm->pasid style of SVA is explicitly enabled through
>> iommu_dev_enable_feature(IOMMU_DEV_FEAT_SVA). The IOMMU driver
>> specific
>> restriction might be put there?
>>
>>>
>>> too many returns in this function, maybe setup all returns to the end of
>>> the function might be elegant?
>>
>> I didn't find cleanup room after a quick scan of the code. But sure, let
>> me go through code again offline.
>>
>
> If we do care:
>
> +static u32 dev_iommu_get_max_pasids(struct device *dev)
> +{
> + u32 max_pasids = 0,
> + u32 num_bits = 0;
> + int ret;
> +
> + if (dev_is_pci(dev)) {
> + ret = pci_max_pasids(to_pci_dev(dev));
> + if (ret > 0)
> + max_pasids = ret;
> + } else {
> + ret = device_property_read_u32(dev, "pasid-num-bits", &num_bits);
> + if (!ret)
> + max_pasids = 1UL << num_bits;
> + }
> +
> + return min_t(u32, max_pasids, dev->iommu->iommu_dev->max_pasids);
> +}
Great! Cleaner and more compact than mine. Thank you!
Best regards,
baolu
Powered by blists - more mailing lists