Received: by 2002:a05:6a10:8c0a:0:0:0:0 with SMTP id go10csp2384010pxb; Sat, 27 Feb 2021 22:44:29 -0800 (PST) X-Google-Smtp-Source: ABdhPJzD8+p3yf+mrOHePgqxEAEzO5XOuu5NJ308BF2+V2HTFUuqkrXaL+3VA8rHGvbstTuHDU8x X-Received: by 2002:a17:907:76ed:: with SMTP id kg13mr10078503ejc.99.1614494669462; Sat, 27 Feb 2021 22:44:29 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1614494669; cv=none; d=google.com; s=arc-20160816; b=BGxL0pYdGdOpWFqVo1K8D29ffuNnYxOfecT4dM88rdwbFYac/GXbHlrNVtoJtfBkSm 45TNm57XyeTPdPoeINPv40lrtEg9QzZg9oyQZh+OQbc2rAWcARhurkXk5QWoNumBVTRo QuaTb4UtF1AZmj0fnaUNjZPkgbqn9N0MEI+d0TwulNXWDNqr5mzmFz/0Qv1ZhEIZ2d3n 5sxD3UOUe4jbWt1BDLjdefMvn0U5EGK4QkEg/yQwTksMET3c9xuJA955yuoG8LF6sCx+ A0oUA+YNHFiYTNVyIUEu6m08bk0ExeTDv0LOkEbmvZhM+WyuJtrf7LVenjMEUqSHrqfU TzfA== 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:ironport-sdr:ironport-sdr; bh=9n46KzE7Hv5vU8u/ObAwi6+Y6eHumlm0W87RIF9570c=; b=Ltzqnlo7k2aXIhKgcGZ0nsC83dbQ7IPQZMNHyHSIQcgK1GnYw2Kr3KpINZdfb78lrq x2iXu8xZbZV2ItLbnDUYrg0pkggUlDSM/8rOAAxh0EWwCqIWY/46BSv7E3gbZjM+w03p fBQS52NP9Bjxe1Nr/fTGViq5xMhNHN9EBbgKqY/eNIIqn55gKa5hV0vMpoacjlpPHSwW WbKVMA/oQN2kigw0Y/ivwrf6ogbohjKq5h8dgjfEFew6N5orPx2uyVaaz00kbGy+umQM blh284aGefPfsVN0o9mnxlrkqmRSL858Xe8W8ODibrIdO0RIp53HY3NzFCLr8qSm4nOH 1FxQ== ARC-Authentication-Results: i=1; mx.google.com; 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=fail (p=NONE sp=NONE dis=NONE) header.from=intel.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id v4si9847119edj.37.2021.02.27.22.44.07; Sat, 27 Feb 2021 22:44:29 -0800 (PST) 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; 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=fail (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230444AbhB1Gn2 (ORCPT + 99 others); Sun, 28 Feb 2021 01:43:28 -0500 Received: from mga09.intel.com ([134.134.136.24]:22647 "EHLO mga09.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231133AbhB1Gmh (ORCPT ); Sun, 28 Feb 2021 01:42:37 -0500 IronPort-SDR: Gcu4fLdgVpeUKsyGAnuHFZ6KhJK10DDgazZjYxuOQoOuEKJWDoL5/1LKmKrSGQlYWuNe7V4pNB o0r+AzSHzqoA== X-IronPort-AV: E=McAfee;i="6000,8403,9908"; a="186323911" X-IronPort-AV: E=Sophos;i="5.81,211,1610438400"; d="scan'208";a="186323911" Received: from orsmga004.jf.intel.com ([10.7.209.38]) by orsmga102.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 27 Feb 2021 22:33:10 -0800 IronPort-SDR: /Vzm0YxkFjeFo6ut3o7v8+CqkNKZmbSAXqjq6gYi8tI9Cq3f5u00e2T2qIXbb6ACQZFeTKeC4p 4bI+20WBl1Cg== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.81,211,1610438400"; d="scan'208";a="517029743" Received: from otc-wp-03.jf.intel.com ([10.54.39.79]) by orsmga004.jf.intel.com with ESMTP; 27 Feb 2021 22:33:10 -0800 From: Jacob Pan To: LKML , Joerg Roedel , "Lu Baolu" , David Woodhouse , iommu@lists.linux-foundation.org, cgroups@vger.kernel.org, Tejun Heo , Li Zefan , Johannes Weiner , Jean-Philippe Brucker Cc: Alex Williamson , Eric Auger , Jason Gunthorpe , Jonathan Corbet , Raj Ashok , "Tian, Kevin" , Yi Liu , Wu Hao , Dave Jiang , Jacob Pan Subject: [RFC PATCH 16/18] iommu/ioasid: Consult IOASIDs cgroup for allocation Date: Sat, 27 Feb 2021 14:01:24 -0800 Message-Id: <1614463286-97618-17-git-send-email-jacob.jun.pan@linux.intel.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1614463286-97618-1-git-send-email-jacob.jun.pan@linux.intel.com> References: <1614463286-97618-1-git-send-email-jacob.jun.pan@linux.intel.com> Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Once IOASIDs cgroup is active, we must consult the limitation set up by the cgroups during allocation. Freeing IOASIDs also need to return the quota back to the cgroup. Signed-off-by: Jacob Pan --- drivers/iommu/ioasid.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/drivers/iommu/ioasid.c b/drivers/iommu/ioasid.c index d42b39ca2c8b..fd3f5729c71d 100644 --- a/drivers/iommu/ioasid.c +++ b/drivers/iommu/ioasid.c @@ -782,7 +782,10 @@ ioasid_t ioasid_alloc(struct ioasid_set *set, ioasid_t min, ioasid_t max, spin_lock(&ioasid_allocator_lock); /* Check if the IOASID set has been allocated and initialized */ - if (!ioasid_set_is_valid(set)) + if (!set || !ioasid_set_is_valid(set)) + goto done_unlock; + + if (set->type == IOASID_SET_TYPE_MM && ioasid_cg_charge(set)) goto done_unlock; if (set->quota <= atomic_read(&set->nr_ioasids)) { @@ -832,6 +835,7 @@ ioasid_t ioasid_alloc(struct ioasid_set *set, ioasid_t min, ioasid_t max, goto done_unlock; exit_free: kfree(data); + ioasid_cg_uncharge(set); done_unlock: spin_unlock(&ioasid_allocator_lock); return id; @@ -849,6 +853,7 @@ static void ioasid_do_free_locked(struct ioasid_data *data) kfree_rcu(ioasid_data, rcu); } atomic_dec(&data->set->nr_ioasids); + ioasid_cg_uncharge(data->set); xa_erase(&data->set->xa, data->id); /* Destroy the set if empty */ if (!atomic_read(&data->set->nr_ioasids)) -- 2.25.1