From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754127AbcLFR3Y (ORCPT ); Tue, 6 Dec 2016 12:29:24 -0500 Received: from mga03.intel.com ([134.134.136.65]:8825 "EHLO mga03.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1754081AbcLFR3V (ORCPT ); Tue, 6 Dec 2016 12:29:21 -0500 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.33,310,1477983600"; d="scan'208";a="909335869" Date: Tue, 6 Dec 2016 09:30:08 -0800 From: Jacob Pan To: Joerg Roedel Cc: iommu@lists.linux-foundation.org, LKML , David Woodhouse , Raj Ashok , Mika Kuoppala , jacob.jun.pan@linux.intel.com Subject: Re: [PATCH] iommu/intel-iommu: fix pasid table size encoding Message-ID: <20161206093008.28d46d07@jacob-builder> In-Reply-To: <20161206163111.GC27203@8bytes.org> References: <1480629026-174113-1-git-send-email-jacob.jun.pan@linux.intel.com> <20161206163111.GC27203@8bytes.org> Organization: OTC X-Mailer: Claws Mail 3.13.2 (GTK+ 2.24.30; x86_64-pc-linux-gnu) MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Tue, 6 Dec 2016 17:31:11 +0100 Joerg Roedel wrote: > 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. > Good point. I will make the change. Still keeping the lower bond sanity check to prevent insanely small pss. I initially did the patch w/o knowing David's pasid_max patch in rc7. I was under the impression that pasid_max is a temp solution until we remove the requirement of contiguous memory allocation. Thanks, Jacob