Received: by 2002:a05:6a10:22f:0:0:0:0 with SMTP id 15csp3330495pxk; Mon, 28 Sep 2020 14:42:01 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwX7qC6OzjzOEcDV6KPb+NGT0yM3eDMYO+/JPiLbHO5/+BFiiOme75Onm7L2R/98XLHEmbj X-Received: by 2002:a17:906:71c9:: with SMTP id i9mr755849ejk.250.1601329321551; Mon, 28 Sep 2020 14:42:01 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1601329321; cv=none; d=google.com; s=arc-20160816; b=nLKogQ+LCsPdJxv8y8RfcLF/i7P4vHQhPyQzKDRYErC/Cb8zK0LnZ6QroGQ+IrdaVQ XfI6GE/mqgBEQgixboZoIZHWwuf49NQqKFkffQm6lrhyY/ijAdFvddKhCVQexETW1NA+ Tqw95q9QKp2CtqCafwJwGLVjl1wrMrjstZtb6aR2cfmQE9Ow7c9WGtnsv2FeEoT5aIR8 12j0dRKHFHyvnScxMCiKC8DtRw9cAhm5EuGiVapmFdfd3rx+eDSUKyxZFzuL43hZUwIv nUDDIHneXiBsGgTz2VOBmHiJVOaoc6fcbvBzYak6uZD4oB9wXRMwXo71mdhxEFghhR1r 3LYg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:references:in-reply-to:message-id:date:subject :cc:to:from:dkim-signature; bh=k4Am4rbSCn6s1LkiSoS1FQPjQrgQdxus6zxqbBBGArU=; b=kquvs1jPJOXrdYE3V5eikAYub8JdnOtHUi+/y1qVQNacPWJmyBeyL8wP0MbmoOoxH/ +wtj9T5pkkfcpSVSsVAgGcgvrsHxa2XUdK2Wqwi2eSoJg/h81EemQlwebR0NsXutCxWS sgtdlpHUce4aGSKfWMRieWGJU6Qb6BlFFFxYd7GcJG7FCI0D6Z4K1/L5MlOS6NgEw47I Nf+ajGvh0upY9Rej72SVQnx757sbLrqB1XKF2aIp3q73um8273M+59iycsZhFX2Xp7B6 CduzkFN7ZFDhf7UQ8dHub/RjXLZr1HXw18i0L7LmpB/opiTlu9cUvY5VOmK/HzKTlWgR OSXg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=BLa1n7jG; 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=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id ot12si1344545ejb.692.2020.09.28.14.41.38; Mon, 28 Sep 2020 14:42:01 -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=@gmail.com header.s=20161025 header.b=BLa1n7jG; 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=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727059AbgI1VhF (ORCPT + 99 others); Mon, 28 Sep 2020 17:37:05 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:49608 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726959AbgI1Vgv (ORCPT ); Mon, 28 Sep 2020 17:36:51 -0400 Received: from mail-pj1-x1041.google.com (mail-pj1-x1041.google.com [IPv6:2607:f8b0:4864:20::1041]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 28567C0613CE; Mon, 28 Sep 2020 14:36:51 -0700 (PDT) Received: by mail-pj1-x1041.google.com with SMTP id q4so1483365pjh.5; Mon, 28 Sep 2020 14:36:51 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=k4Am4rbSCn6s1LkiSoS1FQPjQrgQdxus6zxqbBBGArU=; b=BLa1n7jGZg/z/AUQhN1k1olzszjlGtanGPHXCxNRPvd1gwLxEQQE3EeiKA12Gq27x9 pfkzTNhUWeK9uuZXFNLNsypwqnJXbyrClkTc2gNuacrAxshq+hYNNZZoEKJL8PXdjBQI gnp5UkwcdgU252d0esse9WI/D4jqX1yCT+ajbHg1rkQ9fscftyHh2ucis/aRf8TyP+Iu clw1O4Jms6UvgXvyxcWlTt0qXWPssWIcWPy+KSil9l7e1rB53dafFf5qN3fMtjtdolsz arJhJ+Yokn9KIRMB4FDebkuocwFmWHH3OjWc2qXGe2EPwlI9EzqF0txHvpktDhZabNys Arjg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=k4Am4rbSCn6s1LkiSoS1FQPjQrgQdxus6zxqbBBGArU=; b=kk3aPq9LvmIy9cXGi0HctVf2UXPphWCSqS2vhYIaCJj54DNers8AtLtCaMmbGSxbyZ SuQ+VYDLVpycIJoLhFcSmt3aNqBh+Vv7VaXafJeQ9hs2SSMfRJDn7McCUc7hcOdQhpmf EtqslM8iTtfZ8A7kC7MuN+MTeLvohuY5FjGP3MRClYwM60nJpbpg9OV9NEgLtkbBAYU+ ba6oVvif0kOQzHhTttvdns40wtDmbTjBBAiXDf7ZZ4X0l8yZ+31FVSwFj9jAEjRGz/5m /5QOnbZsX6+qzhcJFjwiVsQ2WybotjmTGz8to85tV6dRNjuTVWkEbVLIZAjNkQur5ION Sanw== X-Gm-Message-State: AOAM531q5hDUruVVfDZLfKYyKrjxJM9jcOCWmNvp8n3p7vB+Ds5YYCeL A5Tv36Ws4OL/P25j1EYi7rk= X-Received: by 2002:a17:90b:611:: with SMTP id gb17mr1013905pjb.71.1601329010674; Mon, 28 Sep 2020 14:36:50 -0700 (PDT) Received: from jacob-builder.jf.intel.com (jfdmzpr04-ext.jf.intel.com. [134.134.137.73]) by smtp.gmail.com with ESMTPSA id l11sm2220864pjf.17.2020.09.28.14.36.49 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Mon, 28 Sep 2020 14:36:50 -0700 (PDT) From: Jacob Pan X-Google-Original-From: Jacob Pan To: iommu@lists.linux-foundation.org, LKML , Joerg Roedel , Alex Williamson , "Lu Baolu" , David Woodhouse , Jonathan Corbet Cc: 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: [PATCH v3 06/14] iommu/ioasid: Introduce API to adjust the quota of an ioasid_set Date: Mon, 28 Sep 2020 14:38:33 -0700 Message-Id: <1601329121-36979-7-git-send-email-jacob.jun.pan@linux.intel.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1601329121-36979-1-git-send-email-jacob.jun.pan@linux.intel.com> References: <1601329121-36979-1-git-send-email-jacob.jun.pan@linux.intel.com> Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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 --- 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) +{ + 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)) { + 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. + */ + 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