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

From: Baolu Lu
Date: Tue Dec 12 2023 - 00:39:33 EST


On 12/12/23 1:38 AM, Jason Gunthorpe wrote:
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)

?

Yes. :-)

Something like,

max(ilog2(table->max_pasid >> PASID_PDE_SHIFT) - 7, 0)

Best regards,
baolu