From: "Huang, Kai" <kai.huang@intel.com>
To: "chenridong@huawei.com" <chenridong@huawei.com>,
"linux-sgx@vger.kernel.org" <linux-sgx@vger.kernel.org>,
"cgroups@vger.kernel.org" <cgroups@vger.kernel.org>,
"mkoutny@suse.com" <mkoutny@suse.com>,
"dave.hansen@linux.intel.com" <dave.hansen@linux.intel.com>,
"haitao.huang@linux.intel.com" <haitao.huang@linux.intel.com>,
"tim.c.chen@linux.intel.com" <tim.c.chen@linux.intel.com>,
"linux-kernel@vger.kernel.org" <linux-kernel@vger.kernel.org>,
"mingo@redhat.com" <mingo@redhat.com>,
"tglx@linutronix.de" <tglx@linutronix.de>,
"tj@kernel.org" <tj@kernel.org>,
"jarkko@kernel.org" <jarkko@kernel.org>,
"Mehta, Sohil" <sohil.mehta@intel.com>,
"hpa@zytor.com" <hpa@zytor.com>, "bp@alien8.de" <bp@alien8.de>,
"x86@kernel.org" <x86@kernel.org>
Cc: "mikko.ylinen@linux.intel.com" <mikko.ylinen@linux.intel.com>,
"seanjc@google.com" <seanjc@google.com>,
"anakrish@microsoft.com" <anakrish@microsoft.com>,
"Zhang, Bo" <zhanb@microsoft.com>,
"kristen@linux.intel.com" <kristen@linux.intel.com>,
"yangjie@microsoft.com" <yangjie@microsoft.com>,
"Li, Zhiquan1" <zhiquan1.li@intel.com>,
"chrisyan@microsoft.com" <chrisyan@microsoft.com>
Subject: Re: [PATCH v16 02/16] cgroup/misc: Add per resource callbacks for CSS events
Date: Tue, 27 Aug 2024 10:45:55 +0000 [thread overview]
Message-ID: <7f078f230face5538206906749e173a2e490b00c.camel@intel.com> (raw)
In-Reply-To: <20240821015404.6038-3-haitao.huang@linux.intel.com>
On Tue, 2024-08-20 at 18:53 -0700, Haitao Huang wrote:
> +/**
> + * misc_cg_set_ops() - register resource specific operations.
> + * @type: Type of the misc res.
> + * @ops: Operations for the given type.
> + *
> + * The callbacks in @ops will not be invoked if the capacity of @type is 0.
> + *
> + * Context: Any context.
> + * Return:
> + * * %0 - Successfully registered the operations.
> + * * %-EINVAL - If @type is invalid, or the operations missing any required callbacks.
> + */
> +int misc_cg_set_ops(enum misc_res_type type, const struct misc_res_ops *ops)
> +{
> + if (!valid_type(type))
> + return -EINVAL;
> +
> + if (!ops)
> + return -EINVAL;
> +
> + if (!ops->alloc) {
> + pr_err("%s: alloc missing\n", __func__);
> + return -EINVAL;
> + }
> +
> + if (!ops->free) {
> + pr_err("%s: free missing\n", __func__);
> + return -EINVAL;
> + }
> +
> + misc_res_ops[type] = ops;
> + return 0;
> +}
> +EXPORT_SYMBOL_GPL(misc_cg_set_ops);
As mentioned in another reply, the export isn't mandatory for SGX cgroup
support due to SGX driver cannot be a module.
But I understand the intention is to treat this in a similar way to
misc_cg_set_capacity() etc which are currently exported.
I have no hard opinion whether to export this one. But if we export this, I
don't quite like the fact that it doesn't accept the NULL ops to allow the
caller to unwind.
But I'll leave to cgroup maintainers.
> +
> /**
> * misc_cg_cancel_charge() - Cancel the charge from the misc cgroup.
> * @type: Misc res type in misc cg to cancel the charge from.
> @@ -439,6 +477,36 @@ static struct cftype misc_cg_files[] = {
> {}
> };
>
> +static inline void _misc_cg_res_free(struct misc_cg *cg, enum misc_res_type last)
> +{
> + enum misc_res_type i;
> +
> + for (i = 0; i <= last; i++)
> + if (misc_res_ops[i] && READ_ONCE(misc_res_capacity[i]))
> + misc_res_ops[i]->free(cg);
> +}
> +
> +static inline int _misc_cg_res_alloc(struct misc_cg *cg)
> +{
> + enum misc_res_type i;
> + int ret;
> +
> + for (i = 0; i < MISC_CG_RES_TYPES; i++) {
> + WRITE_ONCE(cg->res[i].max, MAX_NUM);
> + atomic64_set(&cg->res[i].usage, 0);
> +
> + if (misc_res_ops[i] && READ_ONCE(misc_res_capacity[i])) {
> + ret = misc_res_ops[i]->alloc(cg);
> + if (ret) {
> + _misc_cg_res_free(cg, i);
> + return ret;
> + }
> + }
> + }
> +
> + return 0;
> +}
> +
I don't fully understand why kernel uses READ_ONCE()/WRITE_ONCE() to access
misc_res_capacity[i] and others like 'cg->res[i].max', but it looks weird they
are not used when accessing misc_res_ops[i]?
next prev parent reply other threads:[~2024-08-27 10:46 UTC|newest]
Thread overview: 42+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-08-21 1:53 [PATCH v16 00/16] Add Cgroup support for SGX EPC memory Haitao Huang
2024-08-21 1:53 ` [PATCH v16 01/16] x86/sgx: Replace boolean parameters with enums Haitao Huang
2024-08-21 1:53 ` [PATCH v16 02/16] cgroup/misc: Add per resource callbacks for CSS events Haitao Huang
2024-08-27 10:45 ` Huang, Kai [this message]
2024-08-29 9:25 ` Huang, Kai
2024-08-21 1:53 ` [PATCH v16 03/16] cgroup/misc: Export APIs for SGX driver Haitao Huang
2024-08-27 10:25 ` Huang, Kai
2024-08-21 1:53 ` [PATCH v16 04/16] cgroup/misc: Add SGX EPC resource type Haitao Huang
2024-08-21 1:53 ` [PATCH v16 05/16] x86/sgx: Implement basic EPC misc cgroup functionality Haitao Huang
2024-08-27 10:21 ` Huang, Kai
2024-08-27 23:11 ` Huang, Kai
2024-08-28 0:01 ` Huang, Kai
2024-08-21 1:53 ` [PATCH v16 06/16] x86/sgx: Add sgx_epc_lru_list to encapsulate LRU list Haitao Huang
2024-08-21 1:53 ` [PATCH v16 07/16] x86/sgx: Abstract tracking reclaimable pages in LRU Haitao Huang
2024-08-21 1:53 ` [PATCH v16 08/16] x86/sgx: Encapsulate uses of the global LRU Haitao Huang
2024-08-27 11:13 ` Huang, Kai
2024-08-27 23:58 ` Huang, Kai
2024-08-27 18:15 ` Jarkko Sakkinen
2024-08-21 1:53 ` [PATCH v16 09/16] x86/sgx: Add basic EPC reclamation flow for cgroup Haitao Huang
2024-08-22 4:00 ` Haitao Huang
2024-08-27 18:15 ` Jarkko Sakkinen
2024-08-27 23:42 ` Huang, Kai
2024-08-21 1:53 ` [PATCH v16 10/16] x86/sgx: Implement async reclamation " Haitao Huang
2024-08-27 10:22 ` Huang, Kai
2024-08-27 23:46 ` Huang, Kai
2024-08-27 18:15 ` Jarkko Sakkinen
2024-08-21 1:53 ` [PATCH v16 11/16] x86/sgx: Charge mem_cgroup for per-cgroup reclamation Haitao Huang
2024-08-21 1:54 ` [PATCH v16 12/16] x86/sgx: Revise global reclamation for EPC cgroups Haitao Huang
2024-08-27 11:32 ` Huang, Kai
2024-08-27 23:29 ` Huang, Kai
2024-08-27 18:16 ` Jarkko Sakkinen
2024-08-21 1:54 ` [PATCH v16 13/16] x86/sgx: implement direct reclamation for cgroups Haitao Huang
2024-08-27 18:16 ` Jarkko Sakkinen
2024-08-27 23:55 ` Huang, Kai
2024-08-29 9:34 ` Huang, Kai
2024-08-21 1:54 ` [PATCH v16 14/16] x86/sgx: Turn on per-cgroup EPC reclamation Haitao Huang
2024-08-27 23:25 ` Huang, Kai
2024-08-21 1:54 ` [PATCH v16 15/16] Docs/x86/sgx: Add description for cgroup support Haitao Huang
2024-08-21 1:54 ` [PATCH v16 16/16] selftests/sgx: Add scripts for EPC cgroup testing Haitao Huang
2024-08-27 23:26 ` Huang, Kai
2024-08-26 10:57 ` [PATCH v16 00/16] Add Cgroup support for SGX EPC memory Mikko Ylinen
2024-08-27 18:18 ` Jarkko Sakkinen
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=7f078f230face5538206906749e173a2e490b00c.camel@intel.com \
--to=kai.huang@intel.com \
--cc=anakrish@microsoft.com \
--cc=bp@alien8.de \
--cc=cgroups@vger.kernel.org \
--cc=chenridong@huawei.com \
--cc=chrisyan@microsoft.com \
--cc=dave.hansen@linux.intel.com \
--cc=haitao.huang@linux.intel.com \
--cc=hpa@zytor.com \
--cc=jarkko@kernel.org \
--cc=kristen@linux.intel.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-sgx@vger.kernel.org \
--cc=mikko.ylinen@linux.intel.com \
--cc=mingo@redhat.com \
--cc=mkoutny@suse.com \
--cc=seanjc@google.com \
--cc=sohil.mehta@intel.com \
--cc=tglx@linutronix.de \
--cc=tim.c.chen@linux.intel.com \
--cc=tj@kernel.org \
--cc=x86@kernel.org \
--cc=yangjie@microsoft.com \
--cc=zhanb@microsoft.com \
--cc=zhiquan1.li@intel.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®