Chen Ridong (4): filescgroup: remove files of dfl_cftypes. filescgroup: rename filescontrol.c to legacy-filescontrol.c filescgroup: rename functions called by file.c misc: add a type of resource to control fd.
Documentation/admin-guide/cgroup-v2.rst | 7 + fs/Makefile | 2 + fs/file.c | 16 +- fs/filescontrol.c | 345 +++--------------------- fs/legacy-filescontrol.c | 335 +++++++++++++++++++++++ fs/misc-filescontrol.c | 66 +++++ include/linux/fdtable.h | 5 + include/linux/filescontrol.h | 44 ++- include/linux/legacy-filescontrol.h | 33 +++ include/linux/misc-filescontrol.h | 21 ++ include/linux/misc_cgroup.h | 4 + kernel/cgroup/misc.c | 4 + 12 files changed, 547 insertions(+), 335 deletions(-) create mode 100644 fs/legacy-filescontrol.c create mode 100644 fs/misc-filescontrol.c create mode 100644 include/linux/legacy-filescontrol.h create mode 100644 include/linux/misc-filescontrol.h
hulk inclusion category: feature bugzilla: https://gitee.com/openeuler/kernel/issues/I8YC6O
----------------------------------------------------------------------
Cgroup v2 will not support filescgroup, so just remove files of dfl_cftypes. Misc will be used to control fd in cgroup v2.
Signed-off-by: Chen Ridong chenridong@huawei.com --- fs/filescontrol.c | 1 - 1 file changed, 1 deletion(-)
diff --git a/fs/filescontrol.c b/fs/filescontrol.c index 0947566b9119..18924673b806 100644 --- a/fs/filescontrol.c +++ b/fs/filescontrol.c @@ -306,7 +306,6 @@ struct cgroup_subsys files_cgrp_subsys = { .css_free = files_cgroup_css_free, .can_attach = files_cgroup_can_attach, .legacy_cftypes = files, - .dfl_cftypes = files, };
/*
hulk inclusion category: feature bugzilla: https://gitee.com/openeuler/kernel/issues/I8YC6O
----------------------------------------------------------------------
To add misc-filescontrol, rename filescontrol.c to legacy-filescontrol.c.
Signed-off-by: Chen Ridong chenridong@huawei.com --- fs/Makefile | 2 +- fs/file.c | 2 +- fs/{filescontrol.c => legacy-filescontrol.c} | 2 +- include/linux/{filescontrol.h => legacy-filescontrol.h} | 6 +++--- 4 files changed, 6 insertions(+), 6 deletions(-) rename fs/{filescontrol.c => legacy-filescontrol.c} (99%) rename include/linux/{filescontrol.h => legacy-filescontrol.h} (93%)
diff --git a/fs/Makefile b/fs/Makefile index db63c24fae57..63a775009093 100644 --- a/fs/Makefile +++ b/fs/Makefile @@ -47,7 +47,7 @@ obj-$(CONFIG_SYSCTL) += drop_caches.o sysctls.o obj-$(CONFIG_DIRTY_PAGES) += dirty_pages.o
obj-$(CONFIG_FHANDLE) += fhandle.o -obj-$(CONFIG_CGROUP_FILES) += filescontrol.o +obj-$(CONFIG_CGROUP_FILES) += legacy-filescontrol.o obj-y += iomap/
obj-y += quota/ diff --git a/fs/file.c b/fs/file.c index 4419f6975c96..00f602c0a6db 100644 --- a/fs/file.c +++ b/fs/file.c @@ -19,7 +19,7 @@ #include <linux/bitops.h> #include <linux/spinlock.h> #include <linux/rcupdate.h> -#include <linux/filescontrol.h> +#include <linux/legacy-filescontrol.h> #include <linux/close_range.h> #include <net/sock.h>
diff --git a/fs/filescontrol.c b/fs/legacy-filescontrol.c similarity index 99% rename from fs/filescontrol.c rename to fs/legacy-filescontrol.c index 18924673b806..a9d643bfcf5f 100644 --- a/fs/filescontrol.c +++ b/fs/legacy-filescontrol.c @@ -16,7 +16,7 @@ */
#include <linux/page_counter.h> -#include <linux/filescontrol.h> +#include <linux/legacy-filescontrol.h> #include <linux/cgroup.h> #include <linux/export.h> #include <linux/printk.h> diff --git a/include/linux/filescontrol.h b/include/linux/legacy-filescontrol.h similarity index 93% rename from include/linux/filescontrol.h rename to include/linux/legacy-filescontrol.h index 0274349bd918..c455812264af 100644 --- a/include/linux/filescontrol.h +++ b/include/linux/legacy-filescontrol.h @@ -15,8 +15,8 @@ * GNU General Public License for more details. */
-#ifndef _LINUX_FILESCONTROL_H -#define _LINUX_FILESCONTROL_H +#ifndef _LINUX_LEGACY_FILESCONTROL_H +#define _LINUX_LEGACY_FILESCONTROL_H
#include <linux/fdtable.h>
@@ -41,4 +41,4 @@ static inline int files_cgroup_dup_fds(struct files_struct *newf) { return 0; }; static inline void files_cgroup_put_fd(struct files_struct *files, unsigned int fd) {}; #endif /* CONFIG_CGROUP_FILES */
-#endif /* _LINUX_FILESCONTROL_H */ +#endif /* _LINUX_LEGACY_FILESCONTROL_H */
hulk inclusion category: feature bugzilla: https://gitee.com/openeuler/kernel/issues/I8OIQR
----------------------------------------------------------------------
Functions called at file.c are renamed from files_cgroup_xxx to. files_cg_xxx. Add filescontrol.c to surport misc-filescontrol.
Signed-off-by: Chen Ridong chenridong@huawei.com --- fs/Makefile | 1 + fs/file.c | 18 +++++----- fs/filescontrol.c | 52 +++++++++++++++++++++++++++++ fs/legacy-filescontrol.c | 17 ++-------- include/linux/filescontrol.h | 35 +++++++++++++++++++ include/linux/legacy-filescontrol.h | 11 ------ 6 files changed, 100 insertions(+), 34 deletions(-) create mode 100644 fs/filescontrol.c create mode 100644 include/linux/filescontrol.h
diff --git a/fs/Makefile b/fs/Makefile index 63a775009093..da80fdea2152 100644 --- a/fs/Makefile +++ b/fs/Makefile @@ -48,6 +48,7 @@ obj-$(CONFIG_DIRTY_PAGES) += dirty_pages.o
obj-$(CONFIG_FHANDLE) += fhandle.o obj-$(CONFIG_CGROUP_FILES) += legacy-filescontrol.o +obj-$(CONFIG_CGROUP_FILES) += filescontrol.o obj-y += iomap/
obj-y += quota/ diff --git a/fs/file.c b/fs/file.c index 00f602c0a6db..d560e45fde40 100644 --- a/fs/file.c +++ b/fs/file.c @@ -19,7 +19,7 @@ #include <linux/bitops.h> #include <linux/spinlock.h> #include <linux/rcupdate.h> -#include <linux/legacy-filescontrol.h> +#include <linux/filescontrol.h> #include <linux/close_range.h> #include <net/sock.h>
@@ -338,7 +338,7 @@ struct files_struct *dup_fd(struct files_struct *oldf, unsigned int max_fds, int new_fdt->open_fds = newf->open_fds_init; new_fdt->full_fds_bits = newf->full_fds_bits_init; new_fdt->fd = &newf->fd_array[0]; - files_cgroup_assign(newf); + files_cg_assign(newf);
spin_lock(&oldf->file_lock); old_fdt = files_fdtable(oldf); @@ -403,7 +403,7 @@ struct files_struct *dup_fd(struct files_struct *oldf, unsigned int max_fds, int
rcu_assign_pointer(newf->fdt, new_fdt);
- if (files_cgroup_dup_fds(newf)) { + if (files_cg_dup_fds(newf)) { /* could not get enough FD resources. Need to clean up. */ new_fds = new_fdt->fd; for (i = open_files; i != 0; i--) { @@ -419,7 +419,7 @@ struct files_struct *dup_fd(struct files_struct *oldf, unsigned int max_fds, int } return newf; out_release: - files_cgroup_remove(newf); + files_cg_remove(newf); kmem_cache_free(files_cachep, newf); out: return NULL; @@ -445,7 +445,7 @@ static struct fdtable *close_files(struct files_struct * files) if (set & 1) { struct file * file = xchg(&fdt->fd[i], NULL); if (file) { - files_cgroup_unalloc_fd(files, 1); + files_cg_unalloc_fd(files, 1); filp_close(file, files); cond_resched(); } @@ -454,7 +454,7 @@ static struct fdtable *close_files(struct files_struct * files) set >>= 1; } } - files_cgroup_remove(files); + files_cg_remove(files); return fdt; }
@@ -548,7 +548,7 @@ static int alloc_fd(unsigned start, unsigned end, unsigned flags) */ if (error) goto repeat; - if (files_cgroup_alloc_fd(files, 1)) { + if (files_cg_alloc_fd(files, 1)) { error = -EMFILE; goto out; } @@ -590,7 +590,7 @@ static void __put_unused_fd(struct files_struct *files, unsigned int fd) { struct fdtable *fdt = files_fdtable(files);
- files_cgroup_put_fd(files, fd); + files_cg_put_fd(files, fd); __clear_open_fd(fd, fdt); if (fd < files->next_fd) files->next_fd = fd; @@ -1154,7 +1154,7 @@ __releases(&files->file_lock) goto out; }
- if (!tofree && files_cgroup_alloc_fd(files, 1)) { + if (!tofree && files_cg_alloc_fd(files, 1)) { err = -EMFILE; goto out; } diff --git a/fs/filescontrol.c b/fs/filescontrol.c new file mode 100644 index 000000000000..cc18d0fbd56f --- /dev/null +++ b/fs/filescontrol.c @@ -0,0 +1,52 @@ +/* SPDX-License-Identifier: GPL-2.0-or-later OR BSD-2-Clause */ +/* + * Copyright (c) 2024-2024, Huawei Tech. Co., Ltd. + * + * Author: Ridong Chen chenridong@huawei.com + */ + +#include <linux/fdtable.h> +#include <linux/filescontrol.h> +#include <linux/legacy-filescontrol.h> + +u64 file_cg_count_fds(struct files_struct *files) +{ + int i; + struct fdtable *fdt; + int retval = 0; + + fdt = files_fdtable(files); + for (i = 0; i < DIV_ROUND_UP(fdt->max_fds, BITS_PER_LONG); i++) + retval += hweight64((__u64)fdt->open_fds[i]); + return retval; +} + +int files_cg_alloc_fd(struct files_struct *files, u64 n) +{ + return files_cgroup_alloc_fd(files, n); +} + +void files_cg_unalloc_fd(struct files_struct *files, u64 n) +{ + files_cgroup_unalloc_fd(files, n); +} + +void files_cg_assign(struct files_struct *files) +{ + files_cgroup_assign(files); +} + +void files_cg_remove(struct files_struct *files) +{ + files_cgroup_remove(files); +} + +int files_cg_dup_fds(struct files_struct *newf) +{ + return files_cgroup_dup_fds(newf); +} + +void files_cg_put_fd(struct files_struct *files, unsigned int fd) +{ + files_cgroup_put_fd(files, fd); +} diff --git a/fs/legacy-filescontrol.c b/fs/legacy-filescontrol.c index a9d643bfcf5f..c17501567835 100644 --- a/fs/legacy-filescontrol.c +++ b/fs/legacy-filescontrol.c @@ -17,6 +17,7 @@
#include <linux/page_counter.h> #include <linux/legacy-filescontrol.h> +#include <linux/filescontrol.h> #include <linux/cgroup.h> #include <linux/export.h> #include <linux/printk.h> @@ -94,18 +95,6 @@ static void files_cgroup_css_free(struct cgroup_subsys_state *css) kfree(css_fcg(css)); }
-u64 files_cgroup_count_fds(struct files_struct *files) -{ - int i; - struct fdtable *fdt; - int retval = 0; - - fdt = files_fdtable(files); - for (i = 0; i < DIV_ROUND_UP(fdt->max_fds, BITS_PER_LONG); i++) - retval += hweight64((__u64)fdt->open_fds[i]); - return retval; -} - /* * If attaching this cgroup would overcommit the resource then deny * the attach. If not, attach the file resource into new cgroup. @@ -135,7 +124,7 @@ static int files_cgroup_can_attach(struct cgroup_taskset *tset) from_res = css_res_open_handles(from_css);
spin_lock(&files->file_lock); - num_files = files_cgroup_count_fds(files); + num_files = file_cg_count_fds(files); page_counter_uncharge(from_res, num_files);
if (!page_counter_try_charge(to_res, num_files, &fail_res)) { @@ -211,7 +200,7 @@ int files_cgroup_dup_fds(struct files_struct *newf) if (!files_cgroup_enabled()) return 0; spin_lock(&newf->file_lock); - err = files_cgroup_alloc_fd(newf, files_cgroup_count_fds(newf)); + err = files_cgroup_alloc_fd(newf, file_cg_count_fds(newf)); spin_unlock(&newf->file_lock); return err; } diff --git a/include/linux/filescontrol.h b/include/linux/filescontrol.h new file mode 100644 index 000000000000..7eeb25f8ecb1 --- /dev/null +++ b/include/linux/filescontrol.h @@ -0,0 +1,35 @@ +/* SPDX-License-Identifier: GPL-2.0-or-later OR BSD-2-Clause */ +/* + * Copyright (c) 2024-2024, Huawei Tech. Co., Ltd. + * + * Author: Ridong Chen chenridong@huawei.com + */ + +#ifndef _LINUX_FILESCONTROL_H +#define _LINUX_FILESCONTROL_H + +#include <linux/fdtable.h> + +u64 file_cg_count_fds(struct files_struct *files); + +#ifdef CONFIG_CGROUP_FILES +extern int files_cg_alloc_fd(struct files_struct *files, u64 n); +extern void files_cg_unalloc_fd(struct files_struct *files, u64 n); + +extern void files_cg_assign(struct files_struct *files); +extern void files_cg_remove(struct files_struct *files); + +extern int files_cg_dup_fds(struct files_struct *newf); +extern void files_cg_put_fd(struct files_struct *files, unsigned int fd); +#else /* no CONFIG_CGROUP_FILES */ +static inline int files_cg_alloc_fd(struct files_struct *files, u64 n) { return 0; }; +static inline void files_cg_unalloc_fd(struct files_struct *files, u64 n) {}; + +static inline void files_cg_assign(struct files_struct *files) {}; +static inline void files_cg_remove(struct files_struct *files) {}; + +static inline int files_cg_dup_fds(struct files_struct *newf) { return 0; }; +static inline void files_cg_put_fd(struct files_struct *files, unsigned int fd) {}; +#endif /* CONFIG_CGROUP_FILES */ + +#endif /* _LINUX_FILESCONTROL_H */ diff --git a/include/linux/legacy-filescontrol.h b/include/linux/legacy-filescontrol.h index c455812264af..94914d995b62 100644 --- a/include/linux/legacy-filescontrol.h +++ b/include/linux/legacy-filescontrol.h @@ -20,7 +20,6 @@
#include <linux/fdtable.h>
-#ifdef CONFIG_CGROUP_FILES extern int files_cgroup_alloc_fd(struct files_struct *files, u64 n); extern void files_cgroup_unalloc_fd(struct files_struct *files, u64 n);
@@ -30,15 +29,5 @@ extern void files_cgroup_remove(struct files_struct *files);
extern int files_cgroup_dup_fds(struct files_struct *newf); extern void files_cgroup_put_fd(struct files_struct *files, unsigned int fd); -#else /* no CONFIG_CGROUP_FILES */ -static inline int files_cgroup_alloc_fd(struct files_struct *files, u64 n) { return 0; }; -static inline void files_cgroup_unalloc_fd(struct files_struct *files, u64 n) {}; - -static inline void files_cgroup_assign(struct files_struct *files) {}; -static inline void files_cgroup_remove(struct files_struct *files) {}; - -static inline int files_cgroup_dup_fds(struct files_struct *newf) { return 0; }; -static inline void files_cgroup_put_fd(struct files_struct *files, unsigned int fd) {}; -#endif /* CONFIG_CGROUP_FILES */
#endif /* _LINUX_LEGACY_FILESCONTROL_H */
hulk inclusion category: feature bugzilla: https://gitee.com/openeuler/kernel/issues/I8YC6O
----------------------------------------------------------------------
Misc provides the resource limiting and tracking mechanism for the scalar resources, it is more stable and concise to control fd than filescgroup, which controls fd as independent cgroup, and filescgroup will be abandoned in the future. Interfaces of misc are showed as below.
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 fd 1024
misc.current
A read-only flat-keyed file shown in the all cgroups. It shows the current usage of the resources in the cgroup and its children.
$ cat misc.current fd 3
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 fd max
Limit can be set by:: # echo fd 1 > misc.max
Signed-off-by: Chen Ridong chenridong@huawei.com --- Documentation/admin-guide/cgroup-v2.rst | 7 +++ fs/Makefile | 1 + fs/filescontrol.c | 38 ++++++++++++++ fs/legacy-filescontrol.c | 2 +- fs/misc-filescontrol.c | 66 +++++++++++++++++++++++++ include/linux/fdtable.h | 5 ++ include/linux/filescontrol.h | 1 + include/linux/misc-filescontrol.h | 21 ++++++++ include/linux/misc_cgroup.h | 4 ++ kernel/cgroup/misc.c | 4 ++ 10 files changed, 148 insertions(+), 1 deletion(-) create mode 100644 fs/misc-filescontrol.c create mode 100644 include/linux/misc-filescontrol.h
diff --git a/Documentation/admin-guide/cgroup-v2.rst b/Documentation/admin-guide/cgroup-v2.rst index e998aa071ced..dd92ccba20c2 100644 --- a/Documentation/admin-guide/cgroup-v2.rst +++ b/Documentation/admin-guide/cgroup-v2.rst @@ -2505,6 +2505,13 @@ first, and stays charged to that cgroup until that resource is freed. Migrating a process to a different cgroup does not move the charge to the destination cgroup where the process has moved.
+Misc type explaination +~~~~~~~~~~~~~~~~~~~~~~~ + + MISC_CG_RES_FD + Resource for controling fd. Fd is charged when alloc a new fd or copy files, + and uncharged when file is close or putting unused fd. + Others ------
diff --git a/fs/Makefile b/fs/Makefile index da80fdea2152..f1b15345e6a1 100644 --- a/fs/Makefile +++ b/fs/Makefile @@ -48,6 +48,7 @@ obj-$(CONFIG_DIRTY_PAGES) += dirty_pages.o
obj-$(CONFIG_FHANDLE) += fhandle.o obj-$(CONFIG_CGROUP_FILES) += legacy-filescontrol.o +obj-$(CONFIG_CGROUP_FILES) += misc-filescontrol.o obj-$(CONFIG_CGROUP_FILES) += filescontrol.o obj-y += iomap/
diff --git a/fs/filescontrol.c b/fs/filescontrol.c index cc18d0fbd56f..935c9e61ea1f 100644 --- a/fs/filescontrol.c +++ b/fs/filescontrol.c @@ -8,6 +8,14 @@ #include <linux/fdtable.h> #include <linux/filescontrol.h> #include <linux/legacy-filescontrol.h> +#include <linux/misc-filescontrol.h> + +struct static_key_false misc_fd_enable_key; + +static inline bool file_cg_misc_enabled(void) +{ + return static_branch_likely(&misc_fd_enable_key); +}
u64 file_cg_count_fds(struct files_struct *files) { @@ -23,30 +31,60 @@ u64 file_cg_count_fds(struct files_struct *files)
int files_cg_alloc_fd(struct files_struct *files, u64 n) { + if (file_cg_misc_enabled()) + return misc_fd_alloc_fd(files, n); + return files_cgroup_alloc_fd(files, n); }
void files_cg_unalloc_fd(struct files_struct *files, u64 n) { + if (file_cg_misc_enabled()) + return misc_fd_unalloc_fd(files, n); + files_cgroup_unalloc_fd(files, n); }
void files_cg_assign(struct files_struct *files) { + if (file_cg_misc_enabled()) + return misc_fd_assign(files); + files_cgroup_assign(files); }
void files_cg_remove(struct files_struct *files) { + if (file_cg_misc_enabled()) + return misc_fd_remove(files); + files_cgroup_remove(files); }
int files_cg_dup_fds(struct files_struct *newf) { + if (file_cg_misc_enabled()) + return misc_fd_dup_fds(newf); + return files_cgroup_dup_fds(newf); }
void files_cg_put_fd(struct files_struct *files, unsigned int fd) { + if (file_cg_misc_enabled()) + return misc_fd_put_fd(files, fd); + files_cgroup_put_fd(files, fd); } + +#ifdef CONFIG_CGROUP_MISC +#include <linux/misc_cgroup.h> +static int __init enable_misc_fd(char *s) +{ + static_branch_enable(&misc_fd_enable_key); + pr_info("file_cg enable misc to control fd\n"); + misc_cg_set_capacity(MISC_CG_RES_FD, U64_MAX); + return 1; +} +__setup("file_cg=misc", enable_misc_fd); +#endif diff --git a/fs/legacy-filescontrol.c b/fs/legacy-filescontrol.c index c17501567835..b3e403d8dcfd 100644 --- a/fs/legacy-filescontrol.c +++ b/fs/legacy-filescontrol.c @@ -115,7 +115,7 @@ static int files_cgroup_can_attach(struct cgroup_taskset *tset)
task_lock(task); files = task->files; - if (!files || files == &init_files) { + if (!files || !files->files_struct || files == &init_files) { task_unlock(task); return 0; } diff --git a/fs/misc-filescontrol.c b/fs/misc-filescontrol.c new file mode 100644 index 000000000000..a3fb27a08f67 --- /dev/null +++ b/fs/misc-filescontrol.c @@ -0,0 +1,66 @@ +// SPDX-License-Identifier: GPL-2.0-or-later OR BSD-2-Clause +/* + * Copyright (c) 2024-2024, Huawei Tech. Co., Ltd. + * + * Author: Ridong Chen chenridong@huawei.com + */ + +#include <linux/misc_cgroup.h> +#include <linux/fdtable.h> +#include <linux/filescontrol.h> +#include <linux/misc-filescontrol.h> + +int misc_fd_alloc_fd(struct files_struct *files, u64 n) +{ + if (files != &init_files) + return misc_cg_try_charge(MISC_CG_RES_FD, files->misc_cg, n); + return 0; +} + +void misc_fd_unalloc_fd(struct files_struct *files, u64 n) +{ + if (files != &init_files) + return misc_cg_uncharge(MISC_CG_RES_FD, files->misc_cg, n); +} + +void misc_fd_assign(struct files_struct *files) +{ + if (files == NULL || files == &init_files) + return; + + files->misc_cg = get_current_misc_cg(); +} + +void misc_fd_remove(struct files_struct *files) +{ + if (files == &init_files) + return; + + spin_lock(&files->file_lock); + put_misc_cg(files->misc_cg); + spin_unlock(&files->file_lock); +} + +int misc_fd_dup_fds(struct files_struct *newf) +{ + int err; + + if (newf == &init_files) + return 0; + + spin_lock(&newf->file_lock); + err = misc_fd_alloc_fd(newf, file_cg_count_fds(newf)); + spin_unlock(&newf->file_lock); + return err; +} + +void misc_fd_put_fd(struct files_struct *files, unsigned int fd) +{ + struct fdtable *fdt = files_fdtable(files); + + if (files == &init_files) + return; + + if (test_bit(fd, fdt->open_fds)) + return misc_fd_unalloc_fd(files, 1); +} diff --git a/include/linux/fdtable.h b/include/linux/fdtable.h index 22b8b03fef6d..d7e90516eb60 100644 --- a/include/linux/fdtable.h +++ b/include/linux/fdtable.h @@ -65,7 +65,12 @@ struct files_struct { unsigned long open_fds_init[1]; unsigned long full_fds_bits_init[1]; struct file __rcu * fd_array[NR_OPEN_DEFAULT]; +#ifdef CONFIG_CGROUP_FILES struct files_cgroup *files_cgroup; +#endif +#if (defined CONFIG_CGROUP_MISC && defined CONFIG_CGROUP_FILES) + struct misc_cg *misc_cg; +#endif };
struct file_operations; diff --git a/include/linux/filescontrol.h b/include/linux/filescontrol.h index 7eeb25f8ecb1..62668b2f75d9 100644 --- a/include/linux/filescontrol.h +++ b/include/linux/filescontrol.h @@ -16,6 +16,7 @@ u64 file_cg_count_fds(struct files_struct *files); extern int files_cg_alloc_fd(struct files_struct *files, u64 n); extern void files_cg_unalloc_fd(struct files_struct *files, u64 n);
+extern struct files_struct init_files; extern void files_cg_assign(struct files_struct *files); extern void files_cg_remove(struct files_struct *files);
diff --git a/include/linux/misc-filescontrol.h b/include/linux/misc-filescontrol.h new file mode 100644 index 000000000000..0aa618c6a6d2 --- /dev/null +++ b/include/linux/misc-filescontrol.h @@ -0,0 +1,21 @@ +/* SPDX-License-Identifier: GPL-2.0-or-later OR BSD-2-Clause */ +/* + * Copyright (c) 2024-2024, Huawei Tech. Co., Ltd. + * + * Author: Ridong Chen chenridong@huawei.com + */ + +#ifndef __MISC_FILESCONTROL_H_ +#define __MISC_FILESCONTROL_H_ + +#include <linux/fdtable.h> +int misc_fd_alloc_fd(struct files_struct *files, u64 n); +void misc_fd_unalloc_fd(struct files_struct *files, u64 n); + +void misc_fd_assign(struct files_struct *files); +void misc_fd_remove(struct files_struct *files); + +int misc_fd_dup_fds(struct files_struct *newf); +void misc_fd_put_fd(struct files_struct *files, unsigned int fd); + +#endif diff --git a/include/linux/misc_cgroup.h b/include/linux/misc_cgroup.h index e799b1f8d05b..5c320679040f 100644 --- a/include/linux/misc_cgroup.h +++ b/include/linux/misc_cgroup.h @@ -17,6 +17,10 @@ enum misc_res_type { MISC_CG_RES_SEV, /* AMD SEV-ES ASIDs resource */ MISC_CG_RES_SEV_ES, +#endif +#ifdef CONFIG_CGROUP_FILES + /* fd for file control */ + MISC_CG_RES_FD, #endif MISC_CG_RES_TYPES }; diff --git a/kernel/cgroup/misc.c b/kernel/cgroup/misc.c index 79a3717a5803..ccd2b04edab3 100644 --- a/kernel/cgroup/misc.c +++ b/kernel/cgroup/misc.c @@ -24,6 +24,10 @@ static const char *const misc_res_name[] = { /* AMD SEV-ES ASIDs resource */ "sev_es", #endif +#ifdef CONFIG_CGROUP_FILES + /* fd for file control */ + "fd", +#endif };
/* Root misc cgroup */