Received: by 2002:a25:6193:0:0:0:0:0 with SMTP id v141csp1094562ybb; Wed, 1 Apr 2020 15:44:58 -0700 (PDT) X-Google-Smtp-Source: APiQypLKsQ0TsCzPwcQC0oo4LeoA5iUbwT0IZ1N5JoWNOIGXrCNHxzMNfXHN0gHyXsoMIa2hVp2e X-Received: by 2002:aca:4082:: with SMTP id n124mr199468oia.112.1585781098262; Wed, 01 Apr 2020 15:44:58 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1585781098; cv=none; d=google.com; s=arc-20160816; b=J7BmcfGXl1aTw29MBO+JrxaR6nh0R6V2G1wK6C47IoNVPpGqUDV4TpsqewWiDQTuW7 7yCtMaYge/PRQV6pDQ2Y41chjaRONM3f4m6+FmF6W2xapvlAIoeIA3S+pRJ3VGAWK8w6 pOnWyyj8wD0sg4teW9aqotD8/hvzwGDZbBSJp11/KUn8ddF7JBz8d7mjhYkwv88xUwja 1LcVRHSgzTznhgPQ12LTlBWX93N08yx2D7BvUHJpGmde/BxeM041/Ob1FrtIKv7FMXP9 7/8KwsDu0zmUyMORI2OQU6a6fh1HlI8Ctjn6Oo2SD34Nra0SN5ur6rFdYNotLxLDANKT J5ew== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :organization:references:in-reply-to:message-id:subject:cc:to:from :date:ironport-sdr:ironport-sdr; bh=d9oFFCeiTUmaW/3qcRQ6h3KQ7ufR0WRbHwcjmpkiosQ=; b=DcspotqCIENmXL+6PiuCl4En7qnNjoi//oTEY93q6cDFhu6gBHyoc/H+20mi+LDUtt itlF6cIWbl+3i0nSdODRt0eG0Hgd4Ac7XdD8j9sK0yF50Yjkx9TN56D6ctGgnDdCv8xj br+Wo1umtViK26FYhyRFqOx/9f/hcbALO/fnH/j8PEte8SQHcXgPnTFTxYe9CRWj4rfb JuiXHmvSRZOS1nsxejJJ6VqivqQMVHskQ7laT5ubaafjlMxki+NYIDxZrP2J6xMuQ3ks 90PgXroc1lWz+WGliMjG7zNcB0JnBGkx5Kd3fPZ13J7bATaq14s0W+oMzl+gGvn/aKH7 PQPg== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=intel.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id e26si1359583oos.76.2020.04.01.15.44.44; Wed, 01 Apr 2020 15:44:58 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2388393AbgDAWo2 (ORCPT + 99 others); Wed, 1 Apr 2020 18:44:28 -0400 Received: from mga04.intel.com ([192.55.52.120]:48593 "EHLO mga04.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2388386AbgDAWo1 (ORCPT ); Wed, 1 Apr 2020 18:44:27 -0400 IronPort-SDR: NNSNTHSGI0Dl6w8YPN4s5KEiu5/Lyd3PTMV5+3Wd/aKAJFUmmoufShgGfz3kkH1JqJtQ+kHmhc fExyRv1bV1zQ== X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from fmsmga002.fm.intel.com ([10.253.24.26]) by fmsmga104.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 01 Apr 2020 15:44:26 -0700 IronPort-SDR: zkdHSM9lj9RG+TCgrQGNl9DJiOh5LdoXcru112HuXNimShCk6VYW+Fmyawdg5b+53sAe07ES/A wXa/65VULsgw== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.72,333,1580803200"; d="scan'208";a="284569522" Received: from jacob-builder.jf.intel.com (HELO jacob-builder) ([10.7.199.155]) by fmsmga002.fm.intel.com with ESMTP; 01 Apr 2020 15:44:25 -0700 Date: Wed, 1 Apr 2020 15:50:13 -0700 From: Jacob Pan To: Jean-Philippe Brucker Cc: Joerg Roedel , Alex Williamson , Lu Baolu , iommu@lists.linux-foundation.org, LKML , David Woodhouse , Jean-Philippe Brucker , Yi Liu , "Tian, Kevin" , Raj Ashok , Christoph Hellwig , Jonathan Cameron , Eric Auger , jacob.jun.pan@linux.intel.com Subject: Re: [PATCH 01/10] iommu/ioasid: Introduce system-wide capacity Message-ID: <20200401155013.7386b2ad@jacob-builder> In-Reply-To: <20200401134552.GD882512@myrica> References: <1585158931-1825-1-git-send-email-jacob.jun.pan@linux.intel.com> <1585158931-1825-2-git-send-email-jacob.jun.pan@linux.intel.com> <20200401134552.GD882512@myrica> 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 Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Hi Jean, On Wed, 1 Apr 2020 15:45:52 +0200 Jean-Philippe Brucker wrote: > On Wed, Mar 25, 2020 at 10:55:22AM -0700, Jacob Pan wrote: > > IOASID is a limited system-wide resource that can be allocated at > > runtime. This limitation can be enumerated during boot. For > > example, on x86 platforms, PCI Process Address Space ID (PASID) > > allocation uses IOASID service. The number of supported PASID bits > > are enumerated by extended capability register as defined in the > > VT-d spec. > > > > This patch adds a helper to set the system capacity, it expected to > > be set during boot prior to any allocation request. > > This one-time setting is a bit awkward. Since multiple IOMMU drivers > may be loaded, this can't be a module_init() thing. And we generally > have multiple SMMU instances in the system. So we'd need to call > install_capacity() only for the first SMMU loaded with an arbitrary > 1<<20, even though each SMMU can support different numbers of PASID > bits. Furthermore, modules such as iommu-sva will want to initialize > their IOASID set at module_init(), which will happen before the SMMU > can set up the capacity, so ioasid_alloc_set() will return an error. > > How about hardcoding ioasid_capacity to 20 bits for now? It's the > PCIe limit and probably won't have to increase for a while. > Sound good. Default to 20 bits but can be adjusted if needed. > Thanks, > Jean > > > > > Signed-off-by: Jacob Pan > > --- > > drivers/iommu/ioasid.c | 15 +++++++++++++++ > > include/linux/ioasid.h | 5 ++++- > > 2 files changed, 19 insertions(+), 1 deletion(-) > > > > diff --git a/drivers/iommu/ioasid.c b/drivers/iommu/ioasid.c > > index 0f8dd377aada..4026e52855b9 100644 > > --- a/drivers/iommu/ioasid.c > > +++ b/drivers/iommu/ioasid.c > > @@ -17,6 +17,21 @@ struct ioasid_data { > > struct rcu_head rcu; > > }; > > > > +static ioasid_t ioasid_capacity; > > +static ioasid_t ioasid_capacity_avail; > > + > > +/* System capacity can only be set once */ > > +void ioasid_install_capacity(ioasid_t total) > > +{ > > + if (ioasid_capacity) { > > + pr_warn("IOASID capacity already set at %d\n", > > ioasid_capacity); > > + return; > > + } > > + > > + ioasid_capacity = ioasid_capacity_avail = total; > > +} > > +EXPORT_SYMBOL_GPL(ioasid_install_capacity); > > + > > /* > > * struct ioasid_allocator_data - Internal data structure to hold > > information > > * about an allocator. There are two types of allocators: > > diff --git a/include/linux/ioasid.h b/include/linux/ioasid.h > > index 6f000d7a0ddc..9711fa0dc357 100644 > > --- a/include/linux/ioasid.h > > +++ b/include/linux/ioasid.h > > @@ -40,7 +40,7 @@ void *ioasid_find(struct ioasid_set *set, > > ioasid_t ioasid, int ioasid_register_allocator(struct > > ioasid_allocator_ops *allocator); void > > ioasid_unregister_allocator(struct ioasid_allocator_ops > > *allocator); int ioasid_set_data(ioasid_t ioasid, void *data); - > > +void ioasid_install_capacity(ioasid_t total); > > #else /* !CONFIG_IOASID */ > > static inline ioasid_t ioasid_alloc(struct ioasid_set *set, > > ioasid_t min, ioasid_t max, void *private) > > @@ -72,5 +72,8 @@ static inline int ioasid_set_data(ioasid_t > > ioasid, void *data) return -ENOTSUPP; > > } > > > > +static inline void ioasid_install_capacity(ioasid_t total) > > +{ > > +} > > #endif /* CONFIG_IOASID */ > > #endif /* __LINUX_IOASID_H */ > > -- > > 2.7.4 > > [Jacob Pan]