Received: by 2002:a05:6a10:6744:0:0:0:0 with SMTP id w4csp4900726pxu; Wed, 21 Oct 2020 08:05:24 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwQFqEfG7w92C5oYhUk02nB6njHnzlsmvCOhN1XdNkQS7gokE515N1acFJjI28LVmBGBcIy X-Received: by 2002:aa7:c586:: with SMTP id g6mr3541648edq.343.1603292723840; Wed, 21 Oct 2020 08:05:23 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1603292723; cv=none; d=google.com; s=arc-20160816; b=GfDFnHgluza93Yi+mLC8TGXEAByZ0RHt+4SY3v2uvhvO0RI/x3QesMrDPqLuJPzJNy gKTvFsly31fyQzrewU7WYsAXuLcw2lS6vH5j6jfogeRX9/7y9807rkeVSxeXO5DjQTJC jfVT7G+NcC3h0pQFrZPavyH6JE13AU/lVBOnqFC/N363f0Z4kf1w6ngdry0XdDNnQPxy 5hsb3dfgGLVW0YKdASQr9Fk3UdQ/KA34L4EDFg8Q03gHeN7xlnVE4cW/a6ElqsndhLTf U7/C/PsSugRdJLjDjPcobPRFUrrP5aamfLBAGRv+TL5vZfE6YZPTgk6cN22u4g9VILaf PYng== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:message-id:subject:cc:to:from:date:dkim-signature; bh=uDhQg/1PwpQnDC2Kzqd7p30WxXAYl/Dt0HzmXyUtUtM=; b=qa5d00L9rzBa0M4qBmuTGrmYzuRepQLShI6MqQndNEEsS14pTWJa8NAhLI0jItm41U 2vIBTTHyohSFCpFqNXboR1+Rjxl3wy5/mPmETX7d/NbJLAQpMA6FaQnZhLVogulqMzBH NAZZNHdYdOfNKCt84JNojr6WZTr7nkZhoHx8jXJv73APbnJK7OwF1oQIeZpj9vbJ2ink VPZqhu6/ZmISwhIs7v3aDhRsVlD1iYS9fvkxBjw26zzyRdtza0rAZSAk9z4ZzdgfKDPh f3cr0kBYGRoEFBQFgEeYMKQJqCfV4dlG7uX6/wY4/0t2s4+2dmZ1zVhCrDcFKxrvTi9w JzTg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=NoGcYBly; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 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. [23.128.96.18]) by mx.google.com with ESMTP id y1si1409031edp.57.2020.10.21.08.05.00; Wed, 21 Oct 2020 08:05:23 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=NoGcYBly; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 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 S2443805AbgJUO5b (ORCPT + 99 others); Wed, 21 Oct 2020 10:57:31 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:41278 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2442021AbgJUO5a (ORCPT ); Wed, 21 Oct 2020 10:57:30 -0400 Received: from mail-ej1-x644.google.com (mail-ej1-x644.google.com [IPv6:2a00:1450:4864:20::644]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 769D9C0613CE for ; Wed, 21 Oct 2020 07:57:30 -0700 (PDT) Received: by mail-ej1-x644.google.com with SMTP id o26so3670399ejc.8 for ; Wed, 21 Oct 2020 07:57:30 -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=uDhQg/1PwpQnDC2Kzqd7p30WxXAYl/Dt0HzmXyUtUtM=; b=NoGcYBlystc010ave+WzAHOpt++dZH1i/YRqz/rXzQfPQOwEAjmaEqQhJaS+WWtMTu 6GVHomUOSTiseTimztfpf+NO3y7sVKox40ScNxOCe56vlQAJNNBkF3qgzhhMc/rZFE2H J1aU0qD1e0TA/fp9RXG49pFSkYRWc5SC3vXLBxW73s3rtQiVpQz0thT1Y/DAawSq8Zf+ l6V9/VQ0P7tG3WEqgMPwvw0JR8YMJemq+RnNArdFxVDpzpmDmI3tbC0Qq13g7nVdqVlk JZPNMSURbeKabzPhg0An0u6KY/iO79UYfkAmm53xgLkTBmxKgbQBDsjT84uufnqcTt0A 7Jbg== 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=uDhQg/1PwpQnDC2Kzqd7p30WxXAYl/Dt0HzmXyUtUtM=; b=rHrBKjYluSsDKihunLcRQ0kKKKXf4tG3pnxbDQC9YbLm6Ti6Z2HLeYz6TgXQjUSMq1 2NejRUaaOnG3rOp9E0BzRmjX+3mbwRdS5ayglgKK+BcSaUYKafRHgPyA09G1cUAuzhFd C8KthJNLoC3ob11LBQvlcwBUlNOHbJIVYYwLqtuI4yID6uP/GuhORDjKYHMU3Lgl/8gL zOrLntBxkfWrVBfQoxgYnZSgMPVKvzglP9nb5nB/6Gii6dwt9TSz+0uLbkZTwP/Cuybw OJLLjGmKZVRcw2uQ7WWv+gNxVGPz0m5LdztayxINxPk8/gE13OQTpP1/zbzjK+L9USfl g7lA== X-Gm-Message-State: AOAM533ZKExfvZLQyOXMTpRRWrvHrXcl7tIqd8mPe47XPi2UGAtpJbwq x+xeU4+o7XGPmy6lhJatqJgsgw== X-Received: by 2002:a17:906:e15:: with SMTP id l21mr4022951eji.509.1603292249135; Wed, 21 Oct 2020 07:57:29 -0700 (PDT) Received: from myrica ([2001:1715:4e26:a7e0:116c:c27a:3e7f:5eaf]) by smtp.gmail.com with ESMTPSA id z2sm110970edr.64.2020.10.21.07.57.27 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 21 Oct 2020 07:57:28 -0700 (PDT) Date: Wed, 21 Oct 2020 16:57:09 +0200 From: Jean-Philippe Brucker To: Jacob Pan Cc: iommu@lists.linux-foundation.org, LKML , Joerg Roedel , Alex Williamson , Lu Baolu , David Woodhouse , Jonathan Corbet , linux-api@vger.kernel.org, Jean-Philippe Brucker , Eric Auger , Jacob Pan , Yi Liu , "Tian, Kevin" , Raj Ashok , Wu Hao , Yi Sun , Dave Jiang , Randy Dunlap Subject: Re: [PATCH v3 06/14] iommu/ioasid: Introduce API to adjust the quota of an ioasid_set Message-ID: <20201021145709.GD1653231@myrica> References: <1601329121-36979-1-git-send-email-jacob.jun.pan@linux.intel.com> <1601329121-36979-7-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: <1601329121-36979-7-git-send-email-jacob.jun.pan@linux.intel.com> Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Mon, Sep 28, 2020 at 02:38:33PM -0700, Jacob Pan wrote: > Each ioasid_set is given a quota during allocation. As system > administrators balance resources among VMs, we shall support the > adjustment of quota at runtime. The new quota cannot be less than the > outstanding IOASIDs already allocated within the set. The extra quota > will be returned to the system-wide IOASID pool if the new quota is > smaller than the existing one. > > Signed-off-by: Jacob Pan Minor comments below, but Reviewed-by: Jean-Philippe Brucker > --- > drivers/iommu/ioasid.c | 47 +++++++++++++++++++++++++++++++++++++++++++++++ > include/linux/ioasid.h | 6 ++++++ > 2 files changed, 53 insertions(+) > > diff --git a/drivers/iommu/ioasid.c b/drivers/iommu/ioasid.c > index 61e25c2375ab..cf8c7d34e2de 100644 > --- a/drivers/iommu/ioasid.c > +++ b/drivers/iommu/ioasid.c > @@ -654,6 +654,53 @@ void ioasid_set_put(struct ioasid_set *set) > EXPORT_SYMBOL_GPL(ioasid_set_put); > > /** > + * ioasid_adjust_set - Adjust the quota of an IOASID set > + * @set: IOASID set to be assigned > + * @quota: Quota allowed in this set > + * > + * Return 0 on success. If the new quota is smaller than the number of > + * IOASIDs already allocated, -EINVAL will be returned. No change will be > + * made to the existing quota. > + */ > +int ioasid_adjust_set(struct ioasid_set *set, int quota) @quota probably doesn't need to be signed (since it's the same as an ioasid_t, which is unsigned). > +{ > + int ret = 0; > + > + if (quota <= 0) > + return -EINVAL; > + > + spin_lock(&ioasid_allocator_lock); > + if (set->nr_ioasids > quota) { > + pr_err("New quota %d is smaller than outstanding IOASIDs %d\n", > + quota, set->nr_ioasids); > + ret = -EINVAL; > + goto done_unlock; > + } > + > + if ((quota > set->quota) && > + (quota - set->quota > ioasid_capacity_avail)) { misaligned > + ret = -ENOSPC; > + goto done_unlock; > + } > + > + /* Return the delta back to system pool */ > + ioasid_capacity_avail += set->quota - quota; > + > + /* > + * May have a policy to prevent giving all available IOASIDs > + * to one set. But we don't enforce here, it should be in the > + * upper layers. > + */ I think here would be OK to check about fairness. But anyway, we don't have to worry about this yet, so I'd just drop the comment. Thanks, Jean > + set->quota = quota; > + > +done_unlock: > + spin_unlock(&ioasid_allocator_lock); > + > + return ret; > +} > +EXPORT_SYMBOL_GPL(ioasid_adjust_set); > + > +/** > * ioasid_find - Find IOASID data > * @set: the IOASID set > * @ioasid: the IOASID to find > diff --git a/include/linux/ioasid.h b/include/linux/ioasid.h > index 1ae213b660f0..0a5e82148eb9 100644 > --- a/include/linux/ioasid.h > +++ b/include/linux/ioasid.h > @@ -62,6 +62,7 @@ struct ioasid_allocator_ops { > void ioasid_install_capacity(ioasid_t total); > ioasid_t ioasid_get_capacity(void); > struct ioasid_set *ioasid_set_alloc(void *token, ioasid_t quota, int type); > +int ioasid_adjust_set(struct ioasid_set *set, int quota); > void ioasid_set_get(struct ioasid_set *set); > void ioasid_set_put(struct ioasid_set *set); > > @@ -99,6 +100,11 @@ static inline struct ioasid_set *ioasid_set_alloc(void *token, ioasid_t quota, i > return ERR_PTR(-ENOTSUPP); > } > > +static inline int ioasid_adjust_set(struct ioasid_set *set, int quota) > +{ > + return -ENOTSUPP; > +} > + > static inline void ioasid_set_put(struct ioasid_set *set) > { > } > -- > 2.7.4 >