Re: [PATCH v2 1/6] iommu/vt-d: Setup scalable mode context entry in probe path

From: Jason Gunthorpe
Date: Mon Dec 11 2023 - 12:38:31 EST


On Tue, Dec 05, 2023 at 09:21:58AM +0800, Lu Baolu wrote:
> +/*
> + * Get the PASID directory size for scalable mode context entry.
> + * Value of X in the PDTS field of a scalable mode context entry
> + * indicates PASID directory with 2^(X + 7) entries.
> + */
> +static unsigned long context_get_sm_pds(struct pasid_table *table)
> +{
> + unsigned long pds, max_pde;
> +
> + max_pde = table->max_pasid >> PASID_PDE_SHIFT;
> + pds = find_first_bit(&max_pde, MAX_NR_PASID_BITS);
> + if (pds < 7)
> + return 0;
> +
> + return pds - 7;

This seems like a convoluted way to write
max(ilog2(table-max_pasid) - 7,0)

?

Jason