cgroup: New misc cgroup controller
Subsystems (5)
v3 cover cgroup: New misc cgroup controller
Hello
This patch series is creating a new misc cgroup controller for limiting and tracking of resources which are not abstract like other cgroup controllers.
This controller was initially proposed as encryption_id but after the feedbacks, it is now changed to misc cgroup.
https://lore.kernel.org/lkml/[email protected]/
Changes in RFC v3:
1. Changed implementation to support 64 bit counters.
2. Print kernel logs only once per resource per cgroup.
3. Capacity can be set less than the current usage.
Changes in RFC v2:
1. Documentation fixes.
2. Added kernel log messages.
3. Changed charge API to treat misc_cg as input parameter.
4. Added helper APIs to get and release references on the cgroup.
[1] https://lore.kernel.org/lkml/[email protected]
[2] https://lore.kernel.org/lkml/[email protected]/
Vipin Sharma (2):
cgroup: sev: Add misc cgroup controller
cgroup: sev: Miscellaneous cgroup documentation.
Documentation/admin-guide/cgroup-v1/index.rst | 1 + Documentation/admin-guide/cgroup-v1/misc.rst | 4 + Documentation/admin-guide/cgroup-v2.rst | 69 ++- arch/x86/kvm/svm/sev.c | 65 ++- arch/x86/kvm/svm/svm.h | 1 + include/linux/cgroup_subsys.h | 4 + include/linux/misc_cgroup.h | 130 ++++++ init/Kconfig | 14 + kernel/cgroup/Makefile | 1 + kernel/cgroup/misc.c | 402 ++++++++++++++++++ 10 files changed, 679 insertions(+), 12 deletions(-) create mode 100644 Documentation/admin-guide/cgroup-v1/misc.rst create mode 100644 include/linux/misc_cgroup.h create mode 100644 kernel/cgroup/misc.c
Signature · 1 line
2.30.1.766.gb4fecdf3b7-goog
PATCH v3 1/2 cgroup: sev: Add misc cgroup controller
The Miscellaneous cgroup provides the resource limiting and tracking mechanism for the scalar resources which cannot be abstracted like the other cgroup resources. Controller is enabled by the CONFIG_CGROUP_MISC config option.
The first two resources added to the miscellaneous controller are Secure Encrypted Virtualization (SEV) ASIDs and SEV - Encrypted State (SEV-ES) ASIDs. These limited ASIDs are used for encrypting virtual machines memory on the AMD platform
Miscellaneous controller provides 3 interface files:
misc.capacity
A read-only flat-keyed file shown only in the root cgroup. It shows miscellaneous scalar resources available on the platform along with their quantities::
$ cat misc.capacity sev 50 sev_es 10
misc.current
A read-only flat-keyed file shown in the non-root cgroups. It shows the current usage of the resources in the cgroup and its children::
$ cat misc.current sev 3 sev_es 0
misc.max
A read-write flat-keyed file shown in the non root cgroups. Allowed maximum usage of the resources in the cgroup and its children.::
$ cat misc.max sev max sev_es 4
Limit can be set by::
# echo sev 1 > misc.max
Limit can be set to max by::
# echo sev max > misc.max
Limits can be set more than the capacity value in the misc.capacity file.
--- arch/x86/kvm/svm/sev.c | 65 +++++- arch/x86/kvm/svm/svm.h | 1 + include/linux/cgroup_subsys.h | 4 + include/linux/misc_cgroup.h | 130 +++++++++++ init/Kconfig | 14 ++ kernel/cgroup/Makefile | 1 + kernel/cgroup/misc.c | 402 ++++++++++++++++++++++++++++++++++ 7 files changed, 607 insertions(+), 10 deletions(-) create mode 100644 include/linux/misc_cgroup.h create mode 100644 kernel/cgroup/misc.c
arch/x86/kvm/svm/sev.c +55 -10
@@ -14,6 +14,7 @@#include <linux/psp-sev.h> #include <linux/pagemap.h> #include <linux/swap.h> +#include <linux/misc_cgroup.h> #include <linux/processor.h> #include <linux/trace_events.h> #include <asm/fpu/internal.h>
@@ -27,6 +28,21 @@#define __ex (x) __kvm_handle_fault_on_reboot(x) +#ifndef CONFIG_KVM_AMD_SEV +/* +* When this config is not defined, SEV feature is not supported and APIs in +* this file are not used but this file still gets compiled into the KVM AMD +* module. +* +* We will not have MISC_CG_RES_SEV and MISC_CG_RES_SEV_ES entries in the enum +* misc_res_type {} defined in linux/misc_cgroup.h. +* +* Below macros allow compilation to succeed. +*/ +#define MISC_CG_RES_SEV MISC_CG_RES_TYPES +#define MISC_CG_RES_SEV_ES MISC_CG_RES_TYPES +#endif +static u8 sev_enc_bit;static int sev_flush_asids (void );static DECLARE_RWSEM (sev_deactivate_lock);
@@ -88,8 +104,17 @@ static bool __sev_recycle_asids(int min_asid, int max_asid)static int sev_asid_new (struct kvm_sev_info *sev) { -int pos, min_asid, max_asid; +int pos, min_asid, max_asid, ret;bool retry = true; +enum misc_res_type type; + + type = sev->es_active ?MISC_CG_RES_SEV_ES :MISC_CG_RES_SEV ; + sev->misc_cg =get_current_misc_cg (); + ret =misc_cg_try_charge (type, sev->misc_cg,1 ); +if (ret) { +put_misc_cg (sev->misc_cg); +return ret; + }mutex_lock (&sev_bitmap_lock);
@@ -107,7 +132,8 @@ static int sev_asid_new(struct kvm_sev_info *sev) goto again; }mutex_unlock (&sev_bitmap_lock); -return -EBUSY ; + ret = -EBUSY ; + goto e_uncharge; }__set_bit (pos, sev_asid_bitmap);
@@ -115,6 +141,10 @@ static int sev_asid_new(struct kvm_sev_info *sev)mutex_unlock (&sev_bitmap_lock);return pos +1 ; +e_uncharge: +misc_cg_uncharge (type, sev->misc_cg,1 ); +put_misc_cg (sev->misc_cg); +return ret; }static int sev_get_asid (struct kvm *kvm)
@@ -124,14 +154,15 @@ static int sev_get_asid(struct kvm *kvm)return sev->asid; } -static void sev_asid_free (int asid) +static void sev_asid_free (struct kvm_sev_info *sev) {struct svm_cpu_data *sd;int cpu, pos; +enum misc_res_type type;mutex_lock (&sev_bitmap_lock); - pos = asid -1 ; + pos = sev->asid -1 ;__set_bit (pos, sev_reclaim_asid_bitmap);for_each_possible_cpu (cpu) {
@@ -140,6 +171,10 @@ static void sev_asid_free(int asid) }mutex_unlock (&sev_bitmap_lock); + + type = sev->es_active ?MISC_CG_RES_SEV_ES :MISC_CG_RES_SEV ; +misc_cg_uncharge (type, sev->misc_cg,1 ); +put_misc_cg (sev->misc_cg); }static void sev_unbind_asid (struct kvm *kvm,unsigned int handle)
@@ -187,19 +222,19 @@ static int sev_guest_init(struct kvm *kvm, struct kvm_sev_cmd *argp) asid =sev_asid_new (sev);if (asid <0 )return ret; + sev->asid = asid; ret =sev_platform_init (&argp->error);if (ret) goto e_free; sev->active = true; - sev->asid = asid;INIT_LIST_HEAD (&sev->regions_list);return 0 ; e_free: -sev_asid_free (asid); +sev_asid_free (sev);return ret; }
@@ -1243,12 +1278,12 @@ void sev_vm_destroy(struct kvm *kvm)mutex_unlock (&kvm->lock);sev_unbind_asid (kvm, sev->handle); -sev_asid_free (sev->asid); +sev_asid_free (sev); }void __init sev_hardware_setup (void ) { -unsigned int eax, ebx, ecx, edx; +unsigned int eax, ebx, ecx, edx, sev_asid_count, sev_es_asid_count;bool sev_es_supported = false;bool sev_supported = false;
@@ -1280,7 +1315,11 @@ void __init sev_hardware_setup(void)if (!sev_reclaim_asid_bitmap) goto out; -pr_info ("SEV supported: %u ASIDs\n" , max_sev_asid - min_sev_asid +1 ); + sev_asid_count = max_sev_asid - min_sev_asid +1 ; +if (misc_cg_set_capacity (MISC_CG_RES_SEV , sev_asid_count)) + goto out; + +pr_info ("SEV supported: %u ASIDs\n" , sev_asid_count); sev_supported = true;/* SEV-ES support requested? */
@@ -1295,7 +1334,11 @@ void __init sev_hardware_setup(void)if (min_sev_asid ==1 ) goto out; -pr_info ("SEV-ES supported: %u ASIDs\n" , min_sev_asid -1 ); + sev_es_asid_count = min_sev_asid -1 ; +if (misc_cg_set_capacity (MISC_CG_RES_SEV_ES , sev_es_asid_count)) + goto out; + +pr_info ("SEV-ES supported: %u ASIDs\n" , sev_es_asid_count); sev_es_supported = true; out:
@@ -1310,6 +1353,8 @@ void sev_hardware_teardown(void)bitmap_free (sev_asid_bitmap);bitmap_free (sev_reclaim_asid_bitmap); +misc_cg_set_capacity (MISC_CG_RES_SEV ,0 ); +misc_cg_set_capacity (MISC_CG_RES_SEV_ES ,0 );sev_flush_asids (); }
arch/x86/kvm/svm/svm.h +1 -0
@@ -79,6 +79,7 @@ struct kvm_sev_info {unsigned long pages_locked;/* Number of pages locked */ struct list_head regions_list;/* List of registered regions */ u64 ap_jump_table;/* SEV-ES AP Jump Table address */ +struct misc_cg *misc_cg;/* For misc cgroup accounting */ };struct kvm_svm {
include/linux/cgroup_subsys.h +4 -0
@@ -61,6 +61,10 @@ SUBSYS(pids) SUBSYS(rdma)#endif +#if IS_ENABLED (CONFIG_CGROUP_MISC ) +SUBSYS(misc) +#endif +/* * The following subsystems are not supported on the default hierarchy. */
include/linux/misc_cgroup.h new file +130 -0
130 lines not on this page · raw message
init/Kconfig +14 -0
@@ -1105,6 +1105,20 @@ config CGROUP_BPF BPF_CGROUP_INET_INGRESS will be executed on the ingress path of inet sockets. +config CGROUP_MISC + bool "Misc resource controller" + default n + help + Provides a controller for miscellaneous resources on a host. + + Miscellaneous scalar resources are the resources on the host system + which cannot be abstracted like the other cgroups. This controller + tracks and limits the miscellaneous resources used by a process + attached to a cgroup hierarchy. + + For more information, please check misc cgroup section in + /Documentation/admin-guide/cgroup-v2.rst. + config CGROUP_DEBUG bool "Debug controller" default n
kernel/cgroup/Makefile +1 -0
@@ -5,4 +5,5 @@ obj-$(CONFIG_CGROUP_FREEZER) += legacy_freezer.o obj-$(CONFIG_CGROUP_PIDS) += pids.o obj-$(CONFIG_CGROUP_RDMA) += rdma.o obj-$(CONFIG_CPUSETS) += cpuset.o +obj-$(CONFIG_CGROUP_MISC) += misc.o obj-$(CONFIG_CGROUP_DEBUG) += debug.o
kernel/cgroup/misc.c new file +402 -0
402 lines not on this page · raw message
Signature · 1 line
2.30.1.766.gb4fecdf3b7-goog
Michal Koutný
maintainerRe: [Patch v3 1/2] cgroup: sev: Add misc cgroup controller
Hi Vipin.
Quoted 7 lines · Vipin Sharma
arch/x86/kvm/svm/sev.c | 65 +++++- arch/x86/kvm/svm/svm.h | 1 + include/linux/cgroup_subsys.h | 4 + include/linux/misc_cgroup.h | 130 +++++++++++ init/Kconfig | 14 ++ kernel/cgroup/Makefile | 1 + kernel/cgroup/misc.c | 402 ++++++++++++++++++++++++++++++++++
Given different two-fold nature (SEV caller vs misc controller) of some remarks below, I think it makes sense to split this into two patches:
a) generic controller implementation,
b) hooking the controller into SEV ASIDs management.
arch/x86/kvm/svm/sev.c line 38
Quoted 8 lines
arch/x86/kvm/svm/sev.c +8
-0+#ifndef CONFIG_KVM_AMD_SEV +/* +* When this config is not defined, SEV feature is not supported and APIs in +* this file are not used but this file still gets compiled into the KVM AMD +* module. +* +* We will not have MISC_CG_RES_SEV and MISC_CG_RES_SEV_ES entries in the enum +* misc_res_type {} defined in linux/misc_cgroup.h.
BTW, was there any progress on conditioning sev.c build on CONFIG_KVM_AMD_SEV? (So that the defines workaround isn't needeed.)
arch/x86/kvm/svm/sev.c static bool __sev_recycle_asids(int min_asid, int max_asid) · line 113
Quoted 10 lines
static int
sev_asid_new(struct kvm_sev_info *sev){arch/x86/kvm/svm/sev.c +6
-1-int pos, min_asid, max_asid; +int pos, min_asid, max_asid, ret;bool retry = true; +enum misc_res_type type; + + type = sev->es_active ?MISC_CG_RES_SEV_ES :MISC_CG_RES_SEV ; + sev->misc_cg =get_current_misc_cg (); + ret =misc_cg_try_charge (type, sev->misc_cg,1 );
It may be safer to WARN_ON(sev->misc_cg) at this point (see below).
arch/x86/kvm/svm/sev.c static int sev_asid_new(struct kvm_sev_info *sev) · line 147
Quoted 5 lines
[...]
arch/x86/kvm/svm/sev.c +4
-0+e_uncharge: +misc_cg_uncharge (type, sev->misc_cg,1 ); +put_misc_cg (sev->misc_cg); +return ret;
vvv
arch/x86/kvm/svm/sev.c static void sev_asid_free(int asid) · line 177
Quoted 8 lines
arch/x86/kvm/svm/sev.c +4
-0@@ -140,6 +171,10 @@ static void sev_asid_free(int asid) }mutex_unlock (&sev_bitmap_lock); + + type = sev->es_active ?MISC_CG_RES_SEV_ES :MISC_CG_RES_SEV ; +misc_cg_uncharge (type, sev->misc_cg,1 ); +put_misc_cg (sev->misc_cg);
It may be safer to set sev->misc_cg to NULL here.
(IIUC, with current asid_{new,free} calls it shouldn't matter but why to rely on it in the future.)
kernel/cgroup/misc.c line 115
Quoted 4 lines
kernel/cgroup/misc.c new file +3
-0+++ b/kernel/cgroup/misc.c +static void misc_cg_reduce_charge (enum misc_res_type type,struct misc_cg *cg, +unsigned long amount)
misc_cg_cancel_charge seems to be a name more consistent with what we already have in pids and memory controller.
kernel/cgroup/misc.c line 270
Quoted 7 lines
kernel/cgroup/misc.c new file +6
-0+static ssize_t misc_cg_max_write (struct kernfs_open_file *of,char *buf, +size_t nbytes,loff_t off) +{ + +if (!strcmp (MAX_STR , buf)) { + max =ULONG_MAX ;
MAX_NUM for consistency with other places.
kernel/cgroup/misc.c line 280
Quoted 10 lines
kernel/cgroup/misc.c new file +10
-0+ }else { + ret =kstrtoul (buf,0 , &max); +if (ret) +return ret; + } + + cg =css_misc (of_css (of)); + +if (misc_res_capacity[type]) + cg->res[type].max = max;
In theory, parallel writers can clash here, so having the limit atomic type to prevent this would resolve it. See also commit a713af394cf3 ("cgroup: pids: use atomic64_t for pids->limit").
kernel/cgroup/misc.c line 301
Quoted 7 lines
kernel/cgroup/misc.c new file +7
-0+static int misc_cg_current_show (struct seq_file *sf,void *v) +{ +int i; +struct misc_cg *cg =css_misc (seq_css (sf)); + +for (i =0 ; i <MISC_CG_RES_TYPES ; i++) { +if (misc_res_capacity[i])
Since there can be some residual charges after removing capacity (before draining), maybe the condition along the line
if (misc_res_capacity[i] || atomic_long_read(&cg->res[i].usage))
would be more informative for debugging.
kernel/cgroup/misc.c line 325
Quoted 7 lines
kernel/cgroup/misc.c new file +7
-0+static int misc_cg_capacity_show (struct seq_file *sf,void *v) +{ +int i; +unsigned long cap; + +for (i =0 ; i <MISC_CG_RES_TYPES ; i++) { + cap =READ_ONCE (misc_res_capacity[i]);
Why is READ_ONCE only here and not in other places that (actually) check against the set capacity value? Also, there should be a paired WRITE_ONCCE in misc_cg_set_capacity().
Thanks,
Michal
Re: [Patch v3 1/2] cgroup: sev: Add misc cgroup controller
Quoted 4 lines · Michal Koutný
Given different two-fold nature (SEV caller vs misc controller) of some remarks below, I think it makes sense to split this into two patches:
a) generic controller implementation,
b) hooking the controller into SEV ASIDs management.
Sounds good. I will split it.
Quoted 5 lines
kernel/cgroup/misc.c line 280
Quoted 2 lines
kernel/cgroup/misc.c new file +2
-0+if (misc_res_capacity[type]) + cg->res[type].max = max;In theory, parallel writers can clash here, so having the limit atomic type to prevent this would resolve it. See also commit
a713af394cf3("cgroup: pids: useatomic64_tforpids->limit").
We should be fine without atomic64_t because we are using unsigned long and not 64 bit explicitly. This will work on both 32 and 64 bit machines.
But I will add READ_ONCE and WRITE_ONCE because of potential chances of load tearing and store tearing.
Do you agree?
Quoted 10 lines
kernel/cgroup/misc.c line 325
Quoted 7 lines
kernel/cgroup/misc.c new file +7
-0+static int misc_cg_capacity_show (struct seq_file *sf,void *v) +{ +int i; +unsigned long cap; + +for (i =0 ; i <MISC_CG_RES_TYPES ; i++) { + cap =READ_ONCE (misc_res_capacity[i]);Why is
READ_ONCEonly here and not in other places that (actually) check against the set capacity value? Also, there should be a pairedWRITE_ONCCEinmisc_cg_set_capacity().
This was only here to avoid multiple reads of capacity and making sure if condition and seq_print will see the same value. Also, I was not aware of load and store tearing of properly aligned and machine word size variables. I will add READ_ONCE and WRITE_ONCE at other places.
Thanks
Vipin
Michal Koutný
maintainerRe: [Patch v3 1/2] cgroup: sev: Add misc cgroup controller
Quoted 3 lines · Vipin Sharma
We should be fine without
atomic64_tbecause we are using unsigned long and not 64 bit explicitly. This will work on both 32 and 64 bit machines.
I see.
Quoted 4 lines
But I will add
READ_ONCEandWRITE_ONCEbecause of potential chances of load tearing and store tearing.Do you agree?
Yes.
Quoted 2 lines
This was only here to avoid multiple reads of capacity and making sure if condition and
seq_printwill see the same value.
Aha.
Quoted 3 lines
Also, I was not aware of load and store tearing of properly aligned and machine word size variables. I will add
READ_ONCEandWRITE_ONCEat other places.
Yeah, although it's theoretical, I think it also serves well to annotate such unsychronized accesses.
Thanks,
Michal
Re: [Patch v3 1/2] cgroup: sev: Add misc cgroup controller
In reply to Michal KoutnýQuoted 10 lines · Michal Koutný
arch/x86/kvm/svm/sev.c line 38
Quoted 8 lines
arch/x86/kvm/svm/sev.c +8
-0+#ifndef CONFIG_KVM_AMD_SEV +/* +* When this config is not defined, SEV feature is not supported and APIs in +* this file are not used but this file still gets compiled into the KVM AMD +* module. +* +* We will not have MISC_CG_RES_SEV and MISC_CG_RES_SEV_ES entries in the enum +* misc_res_type {} defined in linux/misc_cgroup.h. BTW, was there any progress on conditioning
sev.cbuild onCONFIG_KVM_AMD_SEV? (So that the defines workaround isn't needeed.)
Tom, Brijesh,
Is this something you guys thought about or have some plans to do in the future? Basically to not include sev.c in compilation if CONFIG_KVM_AMD_SEV is disabled.
Michal,
This should not be a blocker for misc controller. This thing can change independent of misc cgroup.
Thanks
Vipin
Sean Christopherson
maintainerRe: [Patch v3 1/2] cgroup: sev: Add misc cgroup controller
Quoted 12 lines · Vipin Sharma
Quoted 10 lines · Michal Koutný
arch/x86/kvm/svm/sev.c line 38
Quoted 8 lines
arch/x86/kvm/svm/sev.c +8
-0+#ifndef CONFIG_KVM_AMD_SEV +/* +* When this config is not defined, SEV feature is not supported and APIs in +* this file are not used but this file still gets compiled into the KVM AMD +* module. +* +* We will not have MISC_CG_RES_SEV and MISC_CG_RES_SEV_ES entries in the enum +* misc_res_type {} defined in linux/misc_cgroup.h. BTW, was there any progress on conditioning
sev.cbuild onCONFIG_KVM_AMD_SEV? (So that the defines workaround isn't needeed.)
Quoted 4 lines
Tom, Brijesh,
Is this something you guys thought about or have some plans to do in the future? Basically to not includesev.cin compilation ifCONFIG_KVM_AMD_SEVis disabled.
It's crossed my mind, but the number of stubs needed made me back off. I'm certainly not opposed to the idea, it's just not a trivial change.
Re: [Patch v3 1/2] cgroup: sev: Add misc cgroup controller
Quoted 13 lines · Sean Christopherson
Quoted 12 lines · Vipin Sharma
Quoted 10 lines · Michal Koutný
arch/x86/kvm/svm/sev.c line 38
Quoted 8 lines
arch/x86/kvm/svm/sev.c +8
-0+#ifndef CONFIG_KVM_AMD_SEV +/* +* When this config is not defined, SEV feature is not supported and APIs in +* this file are not used but this file still gets compiled into the KVM AMD +* module. +* +* We will not have MISC_CG_RES_SEV and MISC_CG_RES_SEV_ES entries in the enum +* misc_res_type {} defined in linux/misc_cgroup.h. BTW, was there any progress on conditioning
sev.cbuild onCONFIG_KVM_AMD_SEV? (So that the defines workaround isn't needeed.)
Quoted 7 lines
Quoted 4 lines
Tom, Brijesh,
Is this something you guys thought about or have some plans to do in the future? Basically to not includesev.cin compilation ifCONFIG_KVM_AMD_SEVis disabled.It's crossed my mind, but the number of stubs needed made me back off. I'm certainly not opposed to the idea, it's just not a trivial change.
Right, I looked at it when I was doing the SEV-ES work and came to the same conclusion.
Thanks,
Tom
Quoted 1 line
Re: [Patch v3 1/2] cgroup: sev: Add misc cgroup controller
In reply to Vipin SharmaHi Vipin,
include/linux/misc_cgroup.h line 10
Quoted 10 lines · Vipin Sharma
include/linux/misc_cgroup.h new file +10
-0+/* SPDX-License-Identifier: GPL-2.0 */ +/* +* Miscellaneous cgroup controller. +* +* Copyright 2020 Google LLC +* Author: Vipin Sharma <[email protected]> +*/ +#ifndef _MISC_CGROUP_H_ +#define _MISC_CGROUP_H_ +
nit: should you do #include <linux/cgroup.h>?
Otherwise, css may be undefined.
Quoted 3 lines
+/**
+ * Types of misc cgroup entries supported by the host.
+ */
Thanks,
Jacob
Re: [Patch v3 1/2] cgroup: sev: Add misc cgroup controller
Quoted 6 lines · Jacob Pan
include/linux/misc_cgroup.h line 10
Quoted 3 lines · Vipin Sharma
include/linux/misc_cgroup.h new file +3
-0+#ifndef _MISC_CGROUP_H_ +#define _MISC_CGROUP_H_ +nit: should you do #include <
linux/cgroup.h>?
Otherwise, css may be undefined.
User of this controller will use get_curernt_misc_cg() API which returns a pointer. Ideally the user should use this pointer and they shouldn't have any need to access "css" in their code. They also don't need to create a object of 'struct misc_cg{}', because that won't be correct misc cgroup object. They should just declare a pointer like we are doing here in 'struct kvm_sev_info {}'.
If they do need to use "css" then they can include cgroup header in their code.
Let me know if I am overlooking something here.
Thanks
Vipin Sharma
Re: [Patch v3 1/2] cgroup: sev: Add misc cgroup controller
Hi Vipin,
Quoted 16 lines · Vipin Sharma
Quoted 7 lines · Jacob Pan
include/linux/misc_cgroup.h line 10
Quoted 3 lines · Vipin Sharma
include/linux/misc_cgroup.h new file +3
-0+#ifndef _MISC_CGROUP_H_ +#define _MISC_CGROUP_H_ +nit: should you do #include <
linux/cgroup.h>?
Otherwise, css may be undefined.User of this controller will use
get_curernt_misc_cg()API which returns a pointer. Ideally the user should use this pointer and they shouldn't have any need to access "css" in their code. They also don't need to create a object of 'struct misc_cg{}', because that won't be correct misc cgroup object. They should just declare a pointer like we are doing here in 'structkvm_sev_info{}'.
Quoted 3 lines
If they do need to use "css" then they can include cgroup header in their code.
I didn't mean the users of misc_cgroup will use css directly. I meant if I want to use misc cgruop in ioasid.c, I have to do the following to avoid undefined css:
#include <linux/cgroup.h>
#include <linux/misc_cgroup.h>
So it might be simpler if you do #include <linux/cgroup.h> inside misc_cgroup.h. Then in ioasid.c, I only need to do #include <linux/misc_cgroup.h>.
Quoted 4 lines
Let me know if I am overlooking something here.
Thanks
Vipin Sharma
Thanks,
Jacob
Re: [Patch v3 1/2] cgroup: sev: Add misc cgroup controller
Quoted 9 lines · Jacob Pan
I didn't mean the users of
misc_cgroupwill use css directly. I meant if I want to use misc cgruop inioasid.c, I have to do the following to avoid undefined css:
#include <linux/cgroup.h>
#include <linux/misc_cgroup.h>So it might be simpler if you do #include <
linux/cgroup.h> insidemisc_cgroup.h. Then inioasid.c, I only need to do #include <linux/misc_cgroup.h>.
Sorry, I misunderstood the comment first time. I agree with you, I will add cgroup header file in the misc_cgroup.h after #ifdef CONFIG_CGROUP_MISC statement.
Thanks
Vipin
PATCH v3 2/2 cgroup: sev: Miscellaneous cgroup documentation.
In reply to Vipin SharmaDocumentation of miscellaneous cgroup controller. This new controller is used to track and limit the usage of scalar resources.
--- Documentation/admin-guide/cgroup-v1/index.rst | 1 + Documentation/admin-guide/cgroup-v1/misc.rst | 4 ++ Documentation/admin-guide/cgroup-v2.rst | 69 ++++++++++++++++++- 3 files changed, 72 insertions(+), 2 deletions(-) create mode 100644 Documentation/admin-guide/cgroup-v1/misc.rst
Documentation/admin-guide/cgroup-v1/index.rst +1 -0
@@ -17,6 +17,7 @@ Control Groups version 1 hugetlb memcg_test memory + misc net_cls net_prio pids
Documentation/admin-guide/cgroup-v1/misc.rst new file +4 -0
@@ -0,0 +1,4 @@ +=============== +Misc controller +=============== +Please refer "Misc" documentation in Documentation/admin-guide/cgroup-v2.rst
Documentation/admin-guide/cgroup-v2.rst +67 -2
81 lines not on this page · raw message
Signature · 1 line
2.30.1.766.gb4fecdf3b7-goog
Tejun Heo
maintainerHello,
Quoted 7 lines · Vipin Sharma
This patch series is creating a new misc cgroup controller for limiting and tracking of resources which are not abstract like other cgroup controllers.
This controller was initially proposed as
encryption_idbut after the feedbacks, it is now changed to misc cgroup.
https://lore.kernel.org/lkml/[email protected]/
Vipin, thank you very much for your persistence and patience. The patchset looks good to me. Michal, as you've been reviewing the series, can you please take another look and ack them if you don't find anything objectionable?
Signature · 1 line
tejun
Michal Koutný
maintainerHello.
Quoted 1 line · Tejun Heo
Vipin, thank you very much for your persistence and patience.
Yes, and thanks for taking my remarks into account.
Quoted 2 lines
Michal, as you've been reviewing the series, can you please take another look and ack them if you don't find anything objectionable?
Honestly, I'm still sitting on the fence whether this needs a new controller and whether the miscontroller (:-p) is a good approach in the long term [1].
I admit, I didn't follow the past dicussions completely, however, (Vipin) could it be in the cover letter/commit messages shortly summarized why cgroups and a controller were chosen to implement restrictions of these resources, what were the alternatives any why were they rejected?
In the previous discussion, I saw the reasoning for the list of the resources to be hardwired in the controller itself in order to get some scrutiny of possible changes. That makes sense to me. But with that, is it necessary to commit to the new controller API via EXPORT_SYMBOL? (I don't mean this as a licensing question but what the external API should be (if any).)
Besides the generic remarks above, I'd still suggest some slight implementation changes, posted inline to the patch.
Thanks,
Michal
[1] Currently, only one thing comes to my mind -- the delegation via cgroup.subtree_control. The miscontroller may add possibly further resources whose delegation granularity is bunched up under one entry.
Tejun Heo
maintainerHello,
Quoted 5 lines · Michal Koutný
Quoted 2 lines
Michal, as you've been reviewing the series, can you please take another look and ack them if you don't find anything objectionable?
Honestly, I'm still sitting on the fence whether this needs a new controller and whether the miscontroller (:-p) is a good approach in the long term [1].
Yeah, it's a bit of cop-out. My take is that the underlying hardware feature isn't mature enough to have reasonable abstraction built on top of them. Given time, maybe future iterations will get there or maybe it's a passing fad and people will mostly forget about these.
In the meantime, keeping them out of cgroup is one direction, a relatively high friction one but still viable. Or we can provide something of a halfway house so that people who have immediate needs can still leverage the existing infrastructure while controlling the amount of time, energy and future lock-ins they take. So, that's misc controller.
I'm somewhat ambivalent but we've had multiple of these things popping up in the past several years and containment seems to be a reasonable approach at this point.
Quoted 3 lines
[1] Currently, only one thing comes to my mind -- the delegation via cgroup.subtree_control. The miscontroller may add possibly further resources whose delegation granularity is bunched up under one entry.
Controller enabling and delegation in themselves aren't supposed to have resource or security implications, so I don't think it's a practical problem.
Thanks.
Signature · 1 line
tejun
Quoted 5 lines · Michal Koutný
I admit, I didn't follow the past dicussions completely, however, (Vipin) could it be in the cover letter/commit messages shortly summarized why cgroups and a controller were chosen to implement restrictions of these resources, what were the alternatives any why were they rejected?
I will add some more information in the cover letter of the next version.
Basically, SEV will mostly be used by cloud providers for providing confidential VMs. Since they are limited we need a good way to schedule these jobs in cloud infrastructure. To achieve this we either come up with some ioctl for "/dev/sev" to know about its usage, availability, etc. This requires existing scheduling mechanism in the cloud to have an extension for this interaction. Now same thing needs to be done for TDX. IBM SEID doesn't have scarcity of this resource but they are also interested in tracking and limiting the usage. Each one coming up with their own interaction is a duplicate effort when they all need similar thing. One can say that abstraction should be at KVM level but these resources can be used outside VM as well.
Most of the cloud infrastructure use cgroups for knowing the host state, track the resources usage, enforce limits on them, etc. They use this info to optimize work allocation in the fleet and make sure no rogue job consumes more than it needs and starves other. Adding these resources to cgroup is a natural choice with least friction. Cgroup itself says it is a mechanism to distribute system resources along the hierarchy in a controlled mechanism and configurable manner. Most of the resources in cgroups are abstracted enough but their are still resources which are not abstract but have limited availability or have specific use cases.
Quoted 7 lines
In the previous discussion, I saw the reasoning for the list of the resources to be hardwired in the controller itself in order to get some scrutiny of possible changes. That makes sense to me. But with that, is it necessary to commit to the new controller API via
EXPORT_SYMBOL? (I don't mean this as a licensing question but what the external API should be (if any).)
As per my understanding this is the only for way for loadable modules (kvm-amd in this case) to access Kernel APIs. Let me know if there is a better way to do it.
Quoted 3 lines
Besides the generic remarks above, I'd still suggest some slight implementation changes, posted inline to the patch.
I will work on them.
I appreciate you guys taking out time and helping me out with this patch series.
Thanks
Vipin
Michal Koutný
maintainerQuoted 1 line · Vipin Sharma
I will add some more information in the cover letter of the next version.
Thanks.
Quoted 2 lines
Each one coming up with their own interaction is a duplicate effort when they all need similar thing.
Could this be expressed as a new BPF hook (when allocating/freeing such a resource unit)?
The decision could be made based on the configured limit or even some other predicate.
(I saw this proposed already but I haven't seen some more reasoning whether it's worse/better. IMO, BPF hooks are "cheaper" than full-blown controllers, though it's still new user API.)
Quoted 3 lines
As per my understanding this is the only for way for loadable modules (kvm-amd in this case) to access Kernel APIs. Let me know if there is a better way to do it.
I understood the symbols are exported for such modularized builds. However, making them non-GPL exposes them to any out-of-tree modules, although, the resource types are supposed to stay hardcoded in the misc controller. So my point was to make them EXPORT_SYMBOL_GPL to mark they're just a means of implementing the modularized builds and not an API. (But they'd remain API for out-of-tree GPL modules anyway, so take this reasoning of mine with a grain of salt.)
Michal
Quoted 9 lines · Michal Koutný
Quoted 1 line · Vipin Sharma
I will add some more information in the cover letter of the next version.
Thanks.
Quoted 2 lines
Each one coming up with their own interaction is a duplicate effort when they all need similar thing.
Could this be expressed as a new BPF hook (when allocating/freeing such a resource unit)?
Quoted 6 lines
The decision could be made based on the configured limit or even some other predicate.
(I saw this proposed already but I haven't seen some more reasoning whether it's worse/better. IMO, BPF hooks are "cheaper" than full-blown controllers, though it's still new user API.)
I am not much knowledgeable with BPF, so, I might be wrong here.
There are couple of things which might not be addressed with BPF:
1. Which controller to use in v1 case? These are not abstract resources so in v1 where each controller have their own hierarchy it might not be easy to identify the best controller.
2. It seems to me that we won't be able to abstract out a single BPF program which can help with all of the resources types we are planning to use, again, because it is not an abstract type like network packets, and there will be different places in the source code to use these resources.
To me a cgroup tends to give much easier and well integrated solution when it comes to scheduling and limiting a resource with existing tools in a cloud infrastructure.
Quoted 5 lines
Quoted 5 lines
As per my understanding this is the only for way for loadable modules (kvm-amd in this case) to access Kernel APIs. Let me know if there is a better way to do it.
Quoted 8 lines
I understood the symbols are exported for such modularized builds. However, making them non-GPL exposes them to any out-of-tree modules, although, the resource types are supposed to stay hardcoded in the misc controller. So my point was to make them
EXPORT_SYMBOL_GPLto mark they're just a means of implementing the modularized builds and not an API. (But they'd remain API for out-of-tree GPL modules anyway, so take this reasoning of mine with a grain of salt.)
I see, I will change it to GPL.
Thanks
Vipin