cgroup: New misc cgroup controller
Subsystems (5)
v4 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 and use cases for other resources, it is now changed to misc cgroup.
https://lore.kernel.org/lkml/20210108012846.4134815-2-vipinsh-hpIqsD4AKlfQT0dZR+AlfA@public.gmane.org/
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 others.
There are resources on a system which are not abstract enough like other cgroup controllers and are available in a limited quantity on a host.
One of them is Secure Encrypted Virtualization (SEV) ASID on AMD CPU. SEV ASIDs are used for creating encrypted VMs. SEV is mostly be used by the cloud providers for providing confidential VMs. Since SEV ASIDs are limited, there is a need to schedule encrypted VMs in a cloud infrastructure based on SEV ASIDs availability and also to limit its usage.
There are similar requirements for other resource types like TDX keys, IOASIDs and SEID.
Adding these resources to a cgroup controller is a natural choice with least amount of 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 there are still some resources which are not abstract but have limited availability or have specific use cases.
Misc controller is a generic controller which can be used by these kinds of resources.
One suggestion was to use BPF for this purpose, however, 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 to use for BPF.
2. Abstracting out a single BPF program which can help with all of the resources types might not be possible, because resources we are working with are not similar and abstract enough, for example network packets, and there will be different places in the source code to use these resources.
A new cgroup controller 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.
Changes in RFC v4:
1. Misc controller patch is split into two patches. One for generic misc controller and second for adding SEV and SEV-ES resource.
2. Using READ_ONCE and WRITE_ONCE for variable accesses.
3. Updated documentation.
4. Changed EXPORT_SYMBOL to EXPORT_SYMBOL_GPL.
5. Included cgroup header in misc_cgroup.h.
6. misc_cg_reduce_charge changed to misc_cg_cancel_charge.
7. misc_cg set to NULL after uncharge.
8. Added WARN_ON if misc_cg not NULL before charging in SEV/SEV-ES.
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/20210218195549.1696769-1-vipinsh-hpIqsD4AKlfQT0dZR+AlfA@public.gmane.org
[2] https://lore.kernel.org/lkml/20210302081705.1990283-1-vipinsh-hpIqsD4AKlfQT0dZR+AlfA@public.gmane.org/
[3] https://lore.kernel.org/lkml/20210304231946.2766648-1-vipinsh-hpIqsD4AKlfQT0dZR+AlfA@public.gmane.org/
Vipin Sharma (3):
cgroup: Add misc cgroup controller
cgroup: Miscellaneous cgroup documentation. svm/sev: Register SEV and SEV-ES ASIDs to the misc controller
Documentation/admin-guide/cgroup-v1/index.rst | 1 + Documentation/admin-guide/cgroup-v1/misc.rst | 4 + Documentation/admin-guide/cgroup-v2.rst | 73 +++- arch/x86/kvm/svm/sev.c | 70 ++- arch/x86/kvm/svm/svm.h | 1 + include/linux/cgroup_subsys.h | 4 + include/linux/misc_cgroup.h | 132 ++++++ init/Kconfig | 14 + kernel/cgroup/Makefile | 1 + kernel/cgroup/misc.c | 407 ++++++++++++++++++ 10 files changed, 695 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.31.0.291.g576ba9dcdaf-goog
PATCH v4 1/3 cgroup: 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.
A resource can be added to the controller via enum misc_res_type{} in the include/linux/misc_cgroup.h file and the corresponding name via misc_res_name[] in the kernel/cgroup/misc.c file. Provider of the resource must set its capacity prior to using the resource by calling misc_cg_set_capacity().
Once a capacity is set then the resource usage can be updated using charge and uncharge APIs. All of the APIs to interact with misc controller are in include/linux/misc_cgroup.h.
Miscellaneous controller provides 3 interface files. If two misc resources (res_a and res_b) are registered then:
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
res_a 50
res_b 10misc.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
res_a 3
res_b 0misc.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
res_a max
res_b 4Limit can be set by::
# echo res_a 1 > misc.max
Limit can be set to max by::
# echo res_a max > misc.max
Limits can be set more than the capacity value in the misc.capacity file.
--- include/linux/cgroup_subsys.h | 4 + include/linux/misc_cgroup.h | 126 +++++++++++ init/Kconfig | 14 ++ kernel/cgroup/Makefile | 1 + kernel/cgroup/misc.c | 401 ++++++++++++++++++++++++++++++++++ 5 files changed, 546 insertions(+) create mode 100644 include/linux/misc_cgroup.h create mode 100644 kernel/cgroup/misc.c
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 +126 -0
126 lines not on this page · raw message
init/Kconfig +14 -0
@@ -1110,6 +1110,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 +401 -0
401 lines not on this page · raw message
Signature · 1 line
2.31.0.291.g576ba9dcdaf-goog
PATCH v4 2/3 cgroup: 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 | 73 ++++++++++++++++++- 3 files changed, 76 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 +71 -2
85 lines not on this page · raw message
Signature · 1 line
2.31.0.291.g576ba9dcdaf-goog
PATCH v4 3/3 svm/sev: Register SEV and SEV-ES ASIDs to the misc controller
In reply to Vipin SharmaSecure Encrypted Virtualization (SEV) and Secure Encrypted Virtualization - Encrypted State (SEV-ES) ASIDs are used to encrypt KVMs on AMD platform. These ASIDs are available in the limited quantities on a host.
Register their capacity and usage to the misc controller for tracking via cgroups.
--- arch/x86/kvm/svm/sev.c | 70 +++++++++++++++++++++++++++++++------ arch/x86/kvm/svm/svm.h | 1 + include/linux/misc_cgroup.h | 6 ++++ kernel/cgroup/misc.c | 6 ++++ 4 files changed, 73 insertions(+), 10 deletions(-)
arch/x86/kvm/svm/sev.c +60 -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>
@@ -28,6 +29,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);
@@ -89,8 +105,19 @@ 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 ; +WARN_ON (sev->misc_cg); + 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); + sev->misc_cg =NULL ; +return ret; + }mutex_lock (&sev_bitmap_lock);
@@ -108,7 +135,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);
@@ -116,6 +144,11 @@ 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); + sev->misc_cg =NULL ; +return ret; }static int sev_get_asid (struct kvm *kvm)
@@ -125,14 +158,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) {
@@ -141,6 +175,11 @@ 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); + sev->misc_cg =NULL ; }static void sev_unbind_asid (struct kvm *kvm,unsigned int handle)
@@ -188,19 +227,20 @@ 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); + sev->asid =0 ;return ret; }
@@ -1315,12 +1355,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;
@@ -1352,7 +1392,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? */
@@ -1367,7 +1411,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:
@@ -1382,6 +1430,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
@@ -65,6 +65,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/misc_cgroup.h +6 -0
@@ -12,6 +12,12 @@* Types of misc cgroup entries supported by the host. */ enum misc_res_type { +#ifdef CONFIG_KVM_AMD_SEV +/* AMD SEV ASIDs resource */ +MISC_CG_RES_SEV , +/* AMD SEV-ES ASIDs resource */ +MISC_CG_RES_SEV_ES , +#endif MISC_CG_RES_TYPES };
kernel/cgroup/misc.c +6 -0
@@ -18,6 +18,12 @@/* Miscellaneous res name, keep it in sync with enum misc_res_type */ static const char *const misc_res_name[] = { +#ifdef CONFIG_KVM_AMD_SEV +/* AMD SEV ASIDs resource */ +"sev" , +/* AMD SEV-ES ASIDs resource */ +"sev_es" , +#endif };/* Root misc cgroup */
Signature · 1 line
2.31.0.291.g576ba9dcdaf-goog
Applied to cgroup/for-5.13. If there are further issues, let's address them incrementally.
Thanks.
Signature · 1 line
tejun
Quoted 8 lines · Tejun Heo
Applied to cgroup/for-5.13. If there are further issues, let's address them incrementally.
Thanks.
--
tejun
Thanks Tejun for accepting and guiding through each version of this patch series.
Quoted 36 lines · Vipin Sharma
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_idbut after the feedbacks and use cases for other resources, it is now changed to misc cgroup.
https://lore.kernel.org/lkml/20210108012846.4134815-2-vipinsh-hpIqsD4AKlfQT0dZR+AlfA@public.gmane.org/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 others.
There are resources on a system which are not abstract enough like other cgroup controllers and are available in a limited quantity on a host.
One of them is Secure Encrypted Virtualization (SEV) ASID on AMD CPU. SEV ASIDs are used for creating encrypted VMs. SEV is mostly be used by the cloud providers for providing confidential VMs. Since SEV ASIDs are limited, there is a need to schedule encrypted VMs in a cloud infrastructure based on SEV ASIDs availability and also to limit its usage.
There are similar requirements for other resource types like TDX keys, IOASIDs and SEID.
Adding these resources to a cgroup controller is a natural choice with least amount of 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 there are still some resources which are not abstract but have limited availability or have specific use cases.
Quoted 2 lines
Misc controller is a generic controller which can be used by these kinds of resources.
Will we make this dynamic? Let resources be registered via something like misc_cg_res_{register,unregister}, at compile time or runtime, instead of hard coded into misc_res_name/misc_res_capacity etc.
There are needs as noted in drmcg session earlier this year. We may make misc cgroup stable, and let device drivers to register their own resources.
This may make misc cgroup controller more complex than expected, but simpler than adding multiple similar controllers.
Quoted 63 lines
One suggestion was to use BPF for this purpose, however, 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 to use for BPF.2. Abstracting out a single BPF program which can help with all of the resources types might not be possible, because resources we are working with are not similar and abstract enough, for example network packets, and there will be different places in the source code to use these resources.
A new cgroup controller 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.
Changes in RFC v4:
1. Misc controller patch is split into two patches. One for generic misc controller and second for adding SEV and SEV-ES resource.
2. UsingREAD_ONCEandWRITE_ONCEfor variable accesses.
3. Updated documentation.
4. ChangedEXPORT_SYMBOLtoEXPORT_SYMBOL_GPL.
5. Included cgroup header inmisc_cgroup.h.
6.misc_cg_reduce_chargechanged tomisc_cg_cancel_charge.
7.misc_cgset to NULL after uncharge.
8. AddedWARN_ONifmisc_cgnot NULL before charging in SEV/SEV-ES.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 treatmisc_cgas input parameter.
4. Added helper APIs to get and release references on the cgroup.[1] https://lore.kernel.org/lkml/20210218195549.1696769-1-vipinsh-hpIqsD4AKlfQT0dZR+AlfA@public.gmane.org
[2] https://lore.kernel.org/lkml/20210302081705.1990283-1-vipinsh-hpIqsD4AKlfQT0dZR+AlfA@public.gmane.org/
[3] https://lore.kernel.org/lkml/20210304231946.2766648-1-vipinsh-hpIqsD4AKlfQT0dZR+AlfA@public.gmane.org/Vipin Sharma (3):
cgroup: Add misc cgroup controller
cgroup: Miscellaneous cgroup documentation. svm/sev: Register SEV and SEV-ES ASIDs to the misc controllerDocumentation/admin-guide/cgroup-v1/index.rst | 1 + Documentation/admin-guide/cgroup-v1/misc.rst | 4 + Documentation/admin-guide/cgroup-v2.rst | 73 +++- arch/x86/kvm/svm/sev.c | 70 ++- arch/x86/kvm/svm/svm.h | 1 + include/linux/cgroup_subsys.h | 4 + include/linux/misc_cgroup.h | 132 ++++++ init/Kconfig | 14 + kernel/cgroup/Makefile | 1 + kernel/cgroup/misc.c | 407 ++++++++++++++++++ 10 files changed, 695 insertions(+), 12 deletions(-)create mode 100644
Documentation/admin-guide/cgroup-v1/misc.rstcreate mode 100644include/linux/misc_cgroup.h
create mode 100644kernel/cgroup/misc.c
Quoted 36 lines · Vipin Sharma
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_idbut after the feedbacks and use cases for other resources, it is now changed to misc cgroup.
https://lore.kernel.org/lkml/20210108012846.4134815-2-vipinsh-hpIqsD4AKlfQT0dZR+AlfA@public.gmane.org/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 others.
There are resources on a system which are not abstract enough like other cgroup controllers and are available in a limited quantity on a host.
One of them is Secure Encrypted Virtualization (SEV) ASID on AMD CPU. SEV ASIDs are used for creating encrypted VMs. SEV is mostly be used by the cloud providers for providing confidential VMs. Since SEV ASIDs are limited, there is a need to schedule encrypted VMs in a cloud infrastructure based on SEV ASIDs availability and also to limit its usage.
There are similar requirements for other resource types like TDX keys, IOASIDs and SEID.
Adding these resources to a cgroup controller is a natural choice with least amount of 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 there are still some resources which are not abstract but have limited availability or have specific use cases.
Quoted 2 lines
Misc controller is a generic controller which can be used by these kinds of resources.
Will we make this dynamic? Let resources be registered via something like misc_cg_res_{register,unregister}, at compile time or runtime, instead of hard coded into misc_res_name/misc_res_capacity etc.
There are needs as noted in drmcg session earlier this year. We may make misc cgroup stable, and let device drivers to register their own resources.
This may make misc cgroup controller more complex than expected, but simpler than adding multiple similar controllers.
Quoted 63 lines
One suggestion was to use BPF for this purpose, however, 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 to use for BPF.2. Abstracting out a single BPF program which can help with all of the resources types might not be possible, because resources we are working with are not similar and abstract enough, for example network packets, and there will be different places in the source code to use these resources.
A new cgroup controller 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.
Changes in RFC v4:
1. Misc controller patch is split into two patches. One for generic misc controller and second for adding SEV and SEV-ES resource.
2. UsingREAD_ONCEandWRITE_ONCEfor variable accesses.
3. Updated documentation.
4. ChangedEXPORT_SYMBOLtoEXPORT_SYMBOL_GPL.
5. Included cgroup header inmisc_cgroup.h.
6.misc_cg_reduce_chargechanged tomisc_cg_cancel_charge.
7.misc_cgset to NULL after uncharge.
8. AddedWARN_ONifmisc_cgnot NULL before charging in SEV/SEV-ES.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 treatmisc_cgas input parameter.
4. Added helper APIs to get and release references on the cgroup.[1] https://lore.kernel.org/lkml/20210218195549.1696769-1-vipinsh-hpIqsD4AKlfQT0dZR+AlfA@public.gmane.org
[2] https://lore.kernel.org/lkml/20210302081705.1990283-1-vipinsh-hpIqsD4AKlfQT0dZR+AlfA@public.gmane.org/
[3] https://lore.kernel.org/lkml/20210304231946.2766648-1-vipinsh-hpIqsD4AKlfQT0dZR+AlfA@public.gmane.org/Vipin Sharma (3):
cgroup: Add misc cgroup controller
cgroup: Miscellaneous cgroup documentation. svm/sev: Register SEV and SEV-ES ASIDs to the misc controllerDocumentation/admin-guide/cgroup-v1/index.rst | 1 + Documentation/admin-guide/cgroup-v1/misc.rst | 4 + Documentation/admin-guide/cgroup-v2.rst | 73 +++- arch/x86/kvm/svm/sev.c | 70 ++- arch/x86/kvm/svm/svm.h | 1 + include/linux/cgroup_subsys.h | 4 + include/linux/misc_cgroup.h | 132 ++++++ init/Kconfig | 14 + kernel/cgroup/Makefile | 1 + kernel/cgroup/misc.c | 407 ++++++++++++++++++ 10 files changed, 695 insertions(+), 12 deletions(-)create mode 100644
Documentation/admin-guide/cgroup-v1/misc.rstcreate mode 100644include/linux/misc_cgroup.h
create mode 100644kernel/cgroup/misc.c
Tejun Heo
maintainerQuoted 10 lines · Xingyou Chen
Quoted 2 lines
Misc controller is a generic controller which can be used by these kinds of resources.
Will we make this dynamic? Let resources be registered via something like misc_cg_res_{register,unregister}, at compile time or runtime, instead of hard coded into misc_res_name/misc_res_capacity etc.
There are needs as noted in drmcg session earlier this year. We may make misc cgroup stable, and let device drivers to register their own resources.
Not too likely given that the need for one-off resources for a specific driver seems to indicate lack of proper abstraction and control mechanism more than anything else. Even for cases where there are genuine needs for per-hardware knobs, I think it's prudent to enforce a review cycle which involves people who aren't directly working on the specific driver.
Thanks.
Signature · 1 line
tejun