From patchwork Mon Oct 30 18:20:03 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Haitao Huang X-Patchwork-Id: 159839 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:d641:0:b0:403:3b70:6f57 with SMTP id cy1csp2415705vqb; Mon, 30 Oct 2023 11:21:54 -0700 (PDT) X-Google-Smtp-Source: AGHT+IFzaXOtBn6IIGeSkviZXiAzng+fB9h2G9hpPEaxnRCOeXDmIZqPRROgsKV0NizXN2Tt9vkg X-Received: by 2002:a17:90a:f015:b0:27d:114e:d4a3 with SMTP id bt21-20020a17090af01500b0027d114ed4a3mr7678920pjb.14.1698690114636; Mon, 30 Oct 2023 11:21:54 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1698690114; cv=none; d=google.com; s=arc-20160816; b=iTJcA4ib5Z8KkTr51nc+cLUgmVVNVnMztTrj6tuWXsDPrm9o7spcBUI5trbHD+UFnR qMkUut04sEsXVzp68ahV7K0vth7jO/lB1NoA6Zzddi3OfAaE9NMIM7M+SXtV34yOHtQa 8+puz7jtRjTSTUTo+Or2Zi4HZ5NcUtjqAap3F7EuUT43Wjfo0x/fBXJ0+5dMVDFbanae zsj1Rre7J6a4UwjX7WIJD3RIwWRGdzFeFrCOQ8JlFBiDCNTbR+ifBEEaSbMbLop/EJF0 KmvcmymzdzP25P3+kmyQPi/KFPOssVurD9zgQY0j0dKqrB6mZ1Ih3e3PmFYVWgjXPdzZ qTpQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=9T/4o0DpIXp2UMK9rr5U9/mFJ3MSvaBuQqv59vNsCWM=; fh=sNqM0rzpS3sahstSbhU1PMo5LJZgUrUMK8BDlDCJMTE=; b=okSohTx0QCWYdNbZf5pbxGZECVRDMMUNIroqLiWqpqE7LEaYjgMylPwNNguZAl5fdS g8Yb/mB8VCqjhP6NOsmcM8KKgPoSZ1jIYi8wQWyB1/vtFwuNQwPVpTzV/Eja4xYHWt9/ Vyasr8PMjIkJtXNhWWw4RG0Pjx1nf3rAl1FJ6sxAz/LAXETOeoRx0QGXiGKIXNt7My/9 0fvYuiPAPY7VhPRCPDQNWJDCJjqbkpgfxx6fk+ZKEnXT5fMnCixss0n92lBUFTAY9hHK CSw8r80o0pepoWF0dTiD1wxA2cwPX9UbqkMOl5Uvi408hjFQwpnD55zoVygatP/fwt3w JP5A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=J1uvufC3; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:8 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: from fry.vger.email (fry.vger.email. [2620:137:e000::3:8]) by mx.google.com with ESMTPS id ca7-20020a17090af30700b002804113621esi2764372pjb.100.2023.10.30.11.21.53 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 30 Oct 2023 11:21:54 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:8 as permitted sender) client-ip=2620:137:e000::3:8; Authentication-Results: mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=J1uvufC3; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:8 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by fry.vger.email (Postfix) with ESMTP id 23D7A8077829; Mon, 30 Oct 2023 11:21:32 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at fry.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232404AbjJ3SUs (ORCPT + 32 others); Mon, 30 Oct 2023 14:20:48 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:33616 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230449AbjJ3SUe (ORCPT ); Mon, 30 Oct 2023 14:20:34 -0400 Received: from mgamail.intel.com (mgamail.intel.com [192.55.52.136]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 9BDECC9; Mon, 30 Oct 2023 11:20:31 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1698690031; x=1730226031; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=lbc5z15jjbdRkyhWfBNnPpmSka2dKIEP/U6WNWcCv9k=; b=J1uvufC3k+kkb07KdbRtvHvWUb5KsOcRkkvEjyuvZuEk5AQlI+PsFT+l yz42QpYKA2ECHv2Jm3jAiV92nXdQHyW1aEkabBpjNoDBy0KJBTQtDwMxi 1OWbzK/5TQTMjPIqLK9Y1zDaT4uO4wTLRPUgPx2JnYO/fZGt/OJEHqF/Z 10Oflc3p8AWKJbV8XJEcN0VxAV8ODXBrevU+RW4Vs8QV2Q4LOP5yBPQve VifZB7S6ML9buXGosA4YSSHdQ26DzhRB+Zl8piVHauZ1jJLeWTrtIsuBd N1hImS3m7ozgwkT21Um1+d/Ga31MISgxRMU0gvRxrWYOTYjqO/d/hvwQL w==; X-IronPort-AV: E=McAfee;i="6600,9927,10879"; a="367479531" X-IronPort-AV: E=Sophos;i="6.03,263,1694761200"; d="scan'208";a="367479531" Received: from orsmga008.jf.intel.com ([10.7.209.65]) by fmsmga106.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 30 Oct 2023 11:20:28 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10879"; a="789529501" X-IronPort-AV: E=Sophos;i="6.03,263,1694761200"; d="scan'208";a="789529501" Received: from b4969161e530.jf.intel.com ([10.165.56.46]) by orsmga008.jf.intel.com with ESMTP; 30 Oct 2023 11:20:28 -0700 From: Haitao Huang To: jarkko@kernel.org, dave.hansen@linux.intel.com, tj@kernel.org, mkoutny@suse.com, linux-kernel@vger.kernel.org, linux-sgx@vger.kernel.org, x86@kernel.org, cgroups@vger.kernel.org, tglx@linutronix.de, mingo@redhat.com, bp@alien8.de, hpa@zytor.com, sohil.mehta@intel.com Cc: zhiquan1.li@intel.com, kristen@linux.intel.com, seanjc@google.com, zhanb@microsoft.com, anakrish@microsoft.com, mikko.ylinen@linux.intel.com, yangjie@microsoft.com, Haitao Huang Subject: [PATCH v6 02/12] cgroup/misc: Export APIs for SGX driver Date: Mon, 30 Oct 2023 11:20:03 -0700 Message-Id: <20231030182013.40086-3-haitao.huang@linux.intel.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20231030182013.40086-1-haitao.huang@linux.intel.com> References: <20231030182013.40086-1-haitao.huang@linux.intel.com> MIME-Version: 1.0 X-Spam-Status: No, score=-1.2 required=5.0 tests=DKIMWL_WL_HIGH,DKIM_SIGNED, DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI, SPF_HELO_NONE,SPF_PASS autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on fry.vger.email Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (fry.vger.email [0.0.0.0]); Mon, 30 Oct 2023 11:21:32 -0700 (PDT) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1781205685881666278 X-GMAIL-MSGID: 1781205685881666278 From: Kristen Carlson Accardi Export misc_cg_root() so the SGX EPC cgroup can access and do extra setup during initialization, e.g., set callbacks and private data previously defined. The SGX EPC cgroup will reclaim EPC pages when a usage in a cgroup reaches its or ancestor's limit. This requires a walk from the current cgroup up to the root similar to misc_cg_try_charge(). Export misc_cg_parent() to enable this walk. Signed-off-by: Kristen Carlson Accardi Co-developed-by: Haitao Huang Signed-off-by: Haitao Huang --- V6: - Make commit messages more concise and split the original patch into two(Kai) --- include/linux/misc_cgroup.h | 24 ++++++++++++++++++++++++ kernel/cgroup/misc.c | 21 ++++++++------------- 2 files changed, 32 insertions(+), 13 deletions(-) diff --git a/include/linux/misc_cgroup.h b/include/linux/misc_cgroup.h index 5dc509c27c3d..2a3b1f8dc669 100644 --- a/include/linux/misc_cgroup.h +++ b/include/linux/misc_cgroup.h @@ -68,6 +68,7 @@ struct misc_cg { struct misc_res res[MISC_CG_RES_TYPES]; }; +struct misc_cg *misc_cg_root(void); u64 misc_cg_res_total_usage(enum misc_res_type type); int misc_cg_set_capacity(enum misc_res_type type, u64 capacity); int misc_cg_try_charge(enum misc_res_type type, struct misc_cg *cg, u64 amount); @@ -87,6 +88,20 @@ static inline struct misc_cg *css_misc(struct cgroup_subsys_state *css) return css ? container_of(css, struct misc_cg, css) : NULL; } +/** + * misc_cg_parent() - Get the parent of the passed misc cgroup. + * @cgroup: cgroup whose parent needs to be fetched. + * + * Context: Any context. + * Return: + * * struct misc_cg* - Parent of the @cgroup. + * * %NULL - If @cgroup is null or the passed cgroup does not have a parent. + */ +static inline struct misc_cg *misc_cg_parent(struct misc_cg *cgroup) +{ + return cgroup ? css_misc(cgroup->css.parent) : NULL; +} + /* * get_current_misc_cg() - Find and get the misc cgroup of the current task. * @@ -111,6 +126,15 @@ static inline void put_misc_cg(struct misc_cg *cg) } #else /* !CONFIG_CGROUP_MISC */ +static inline struct misc_cg *misc_cg_root(void) +{ + return NULL; +} + +static inline struct misc_cg *misc_cg_parent(struct misc_cg *cg) +{ + return NULL; +} static inline u64 misc_cg_res_total_usage(enum misc_res_type type) { diff --git a/kernel/cgroup/misc.c b/kernel/cgroup/misc.c index d971ede44ebf..fa464324ccf8 100644 --- a/kernel/cgroup/misc.c +++ b/kernel/cgroup/misc.c @@ -40,18 +40,13 @@ static struct misc_cg root_cg; static u64 misc_res_capacity[MISC_CG_RES_TYPES]; /** - * parent_misc() - Get the parent of the passed misc cgroup. - * @cgroup: cgroup whose parent needs to be fetched. - * - * Context: Any context. - * Return: - * * struct misc_cg* - Parent of the @cgroup. - * * %NULL - If @cgroup is null or the passed cgroup does not have a parent. + * misc_cg_root() - Return the root misc cgroup. */ -static struct misc_cg *parent_misc(struct misc_cg *cgroup) +struct misc_cg *misc_cg_root(void) { - return cgroup ? css_misc(cgroup->css.parent) : NULL; + return &root_cg; } +EXPORT_SYMBOL_GPL(misc_cg_root); /** * valid_type() - Check if @type is valid or not. @@ -150,7 +145,7 @@ int misc_cg_try_charge(enum misc_res_type type, struct misc_cg *cg, u64 amount) if (!amount) return 0; - for (i = cg; i; i = parent_misc(i)) { + for (i = cg; i; i = misc_cg_parent(i)) { res = &i->res[type]; new_usage = atomic64_add_return(amount, &res->usage); @@ -163,12 +158,12 @@ int misc_cg_try_charge(enum misc_res_type type, struct misc_cg *cg, u64 amount) return 0; err_charge: - for (j = i; j; j = parent_misc(j)) { + for (j = i; j; j = misc_cg_parent(j)) { atomic64_inc(&j->res[type].events); cgroup_file_notify(&j->events_file); } - for (j = cg; j != i; j = parent_misc(j)) + for (j = cg; j != i; j = misc_cg_parent(j)) misc_cg_cancel_charge(type, j, amount); misc_cg_cancel_charge(type, i, amount); return ret; @@ -190,7 +185,7 @@ void misc_cg_uncharge(enum misc_res_type type, struct misc_cg *cg, u64 amount) if (!(amount && valid_type(type) && cg)) return; - for (i = cg; i; i = parent_misc(i)) + for (i = cg; i; i = misc_cg_parent(i)) misc_cg_cancel_charge(type, i, amount); } EXPORT_SYMBOL_GPL(misc_cg_uncharge);