Received: by 2002:a25:6193:0:0:0:0:0 with SMTP id v141csp623847ybb; Wed, 1 Apr 2020 06:48:11 -0700 (PDT) X-Google-Smtp-Source: APiQypJJ2axehES697OfRYaYCGc5ET2pQh2qPUYagkJVa3htdMtso7rQi1xSETzQo7lDh5qGqc+j X-Received: by 2002:aca:4858:: with SMTP id v85mr2691295oia.51.1585748891487; Wed, 01 Apr 2020 06:48:11 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1585748891; cv=none; d=google.com; s=arc-20160816; b=U7g280AOBjg8wBg0/E1otyrq/AodcF8K3LuKBZmLWzfm376cuReP0v4gjafpEOZJP3 0QY7NQpKFRSI/tksHHAriDc3YL7A7AjGDu/preEcJKOlxVzQKk89dc2oe9UJb3Jk+T/R BmaIZE8rNMyfunnIhxHESKgC6f4JLBF1Pkl0xKcLeU9MQQczZ1p+R1wCWIWRdBqtHj1Y KsDYjfIGm/7RCNdKleyV5cC4EYxaDEZg3a3J9m8ZTTdE0Rr/wdo4/jn6Q2fEAPfhttFe sD7UnuEdq0MRj4lUNxpTbNd2K9K7DYwK1EldzS10QlDdrT0HAyiLRPM+4pnxGdodisb6 PQkg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:in-reply-to:content-disposition :mime-version:references:message-id:subject:cc:to:from:date :dkim-signature; bh=4cNryWwLgfk02MQJubNgjaSZbCDMoiiIMtKoOX7YXDI=; b=aDWo3dvWq5C6QAKDzd+LEXD+Kr1jTgg7dLMH8NDQgwEYpq9FJ82QtMobItnmAAKVuv Mhr72nohjqnXGs/DKjQ8lXuNYT+mDblJaMdwORHS/qQF/NpeExdWU28j183ZEJGoTk0N 9/mqa+On1vvNhgpObce0D6qvkqN1N3bkwkym6329OKxUDbjVqi8IWH0LBai1Iay0gDTo 6yj5lQ7o5ckivT1JW9UAd/RolL+/albIO7mOQmSQ3Hx+qB9J7n+OT3Au3pI2yW/eWOac 9q0vSJ33V876MadW+cLN7Qpqvu6U2ysQ68LX22KWi8Tz2cVKX9N4r8ubYVHTO7lsBLrD d0HQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=VteHLmzK; 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=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id d4si907154ood.77.2020.04.01.06.47.57; Wed, 01 Apr 2020 06:48:11 -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; dkim=pass header.i=@linaro.org header.s=google header.b=VteHLmzK; 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=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1732714AbgDANqD (ORCPT + 99 others); Wed, 1 Apr 2020 09:46:03 -0400 Received: from mail-wr1-f66.google.com ([209.85.221.66]:42128 "EHLO mail-wr1-f66.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1732504AbgDANqD (ORCPT ); Wed, 1 Apr 2020 09:46:03 -0400 Received: by mail-wr1-f66.google.com with SMTP id h15so71800wrx.9 for ; Wed, 01 Apr 2020 06:46:02 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to; bh=4cNryWwLgfk02MQJubNgjaSZbCDMoiiIMtKoOX7YXDI=; b=VteHLmzKgoEfzpQT1w/jhX76LESCf+gm4mvr2xXIqiwhTv2TpXWBbt4Y4ZcRFrHXM5 ZH8rUAOdHTvMKVc5NIBAxe5OIiGKoWZlamak03YGSPe1b2LkoLoEDDMyza5RZ+63zO7H MGuKbHbEs5BDD2VJYEB67W0WZgbY4ktCqGKHt70vKyVRIsvcoOefEpLENOV4IQI784b7 h01SahB8bQKpM8MCXHS0DVklDLvM98lHC+3svnbLpIUBQf9ktvVmCfuQx5Le8RNFrWlB 1WZNbK4SIJGcUVYehFgqpdLV3myf8yVjxpuqWFtD6OFnmj0TJKliqsoo4rFebvSMz6dg umEA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to; bh=4cNryWwLgfk02MQJubNgjaSZbCDMoiiIMtKoOX7YXDI=; b=WDJsjcC8G4ZqozXreye66XbNnELQyMlXGIv3TMnYovQyKwS/3ssCFK1UxkW2fJZ9jz pDBpihJZLKQ907YC3wfoA+l6MXxaEoeWAGc+n3dzx1pXnxg0FX36wEQqWw/u3Eo+1I8o 5hlHiwLEVtEP7J+VpSaP9Jzv0Y8//+STRZgh1fteJNyrkdfU9o5k586KozR83ASFq1lo 3f1l4W4Rj6JIrq8lLNb/D1R3+7Y8RpHgZM6VlaD9PxAewIgVNB/fue6q/T+9n7QiLhBI Ui9iMi7JGKeoupfbfuKBUx/CLUjT8pdoQ4WNxBQz80yw7BiTF2CbjPeihG6A3Ur9kX0l I6Cg== X-Gm-Message-State: ANhLgQ2vzOrgIPINamYGwMwfy+Za3Ee6Y2QQSn73iYqwvFRzyZAoIk3g h3Fi/WYUaZ/BHWhjcy91ideQiA== X-Received: by 2002:adf:e44a:: with SMTP id t10mr25806844wrm.322.1585748761807; Wed, 01 Apr 2020 06:46:01 -0700 (PDT) Received: from myrica ([2001:171b:226b:54a0:6097:1406:6470:33b5]) by smtp.gmail.com with ESMTPSA id z1sm3172281wrp.90.2020.04.01.06.46.00 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 01 Apr 2020 06:46:01 -0700 (PDT) Date: Wed, 1 Apr 2020 15:45:52 +0200 From: Jean-Philippe Brucker To: Jacob Pan 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 Subject: Re: [PATCH 01/10] iommu/ioasid: Introduce system-wide capacity Message-ID: <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> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <1585158931-1825-2-git-send-email-jacob.jun.pan@linux.intel.com> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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. 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 >