lkml.org 
[lkml]   [2016]   [Dec]   [6]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
/
Date
From
SubjectRe: [PATCH] iommu/intel-iommu: fix pasid table size encoding
Hi Jacob,

On Thu, Dec 01, 2016 at 01:50:26PM -0800, Jacob Pan wrote:
> diff --git a/drivers/iommu/intel-iommu.c b/drivers/iommu/intel-iommu.c
> index 27596e6..f112aa9 100644
> --- a/drivers/iommu/intel-iommu.c
> +++ b/drivers/iommu/intel-iommu.c
> @@ -5173,6 +5173,29 @@ static void intel_iommu_remove_device(struct device *dev)
> }
>
> #ifdef CONFIG_INTEL_IOMMU_SVM
> +#define MAX_NR_PASID_BITS (20)
> +static inline unsigned long intel_iommu_get_pts(struct intel_iommu *iommu)
> +{
> + unsigned long pts;
> +
> + /*
> + * Convert ecap_pss to extend context entry pts encoding, also
> + * respect the soft pasid_max value set by the iommu.
> + * - number of PASID bits = ecap_pss + 1
> + * - number of PASID table entries = 2^(pts + 5)
> + * Therefore, pts = ecap_pss - 4
> + * e.g. KBL ecap_pss = 0x13, PASID has 20 bits, pts = 15
> + */
> + if (ecap_pss(iommu->ecap) < 5)
> + return 0;
> +
> + pts = (ecap_pss(iommu->ecap) - 4);
> +
> + /* pasid_max is encoded as actual number of entries not the bits */
> + return min(find_first_bit((unsigned long *)&iommu->pasid_max,
> + MAX_NR_PASID_BITS) - 5, pts);

Iommu->max_pasid already depends on ecap_pss(), so I think it is
better to just calculate the pts value as ffs(iommu->max_pasid) - 5.
This way you don't need an extra function and have a simpler
calculation.


Joerg

\
 
 \ /
  Last update: 2016-12-06 17:32    [W:0.057 / U:0.080 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site