cgroup: inline cgroup_task_freeze()
PATCH v2 1/1 cgroup: inline cgroup_task_freeze()
After the introduction of the cgroup.kill there is only one call site of cgroup_task_freeze() left: cgroup_exit(). cgroup_task_freeze() is currently taking rcu_read_lock() to read task's cgroup flags, but because it's always called with css_set_lock locked, the rcu protection is excessive.
Simplify the code by inlining cgroup_task_freeze().
v2: fix build
--- include/linux/cgroup.h | 18 ------------------ kernel/cgroup/cgroup.c | 3 ++- 2 files changed, 2 insertions(+), 19 deletions(-)
include/linux/cgroup.h +0 -18
@@ -906,20 +906,6 @@ void cgroup_freeze(struct cgroup *cgrp, bool freeze);void cgroup_freezer_migrate_task (struct task_struct *task,struct cgroup *src,struct cgroup *dst); -static inline bool cgroup_task_freeze (struct task_struct *task) -{ -bool ret; - -if (task->flags &PF_KTHREAD ) -return false; - -rcu_read_lock (); - ret =test_bit (CGRP_FREEZE , &task_dfl_cgroup (task)->flags); -rcu_read_unlock (); - -return ret; -} -static inline bool cgroup_task_frozen (struct task_struct *task) {return task->frozen;
@@ -929,10 +915,6 @@ static inline bool cgroup_task_frozen(struct task_struct *task)static inline void cgroup_enter_frozen (void ) { }static inline void cgroup_leave_frozen (bool always_leave) { } -static inline bool cgroup_task_freeze (struct task_struct *task) -{ -return false; -}static inline bool cgroup_task_frozen (struct task_struct *task) {return false;
kernel/cgroup/cgroup.c +2 -1
@@ -6267,7 +6267,8 @@ void cgroup_exit(struct task_struct *tsk) cset->nr_tasks--;WARN_ON_ONCE (cgroup_task_frozen (tsk)); -if (unlikely (cgroup_task_freeze (tsk))) +if (unlikely (!(tsk->flags &PF_KTHREAD ) && +test_bit (CGRP_FREEZE , &task_dfl_cgroup (tsk)->flags)))cgroup_update_frozen (task_dfl_cgroup (tsk));spin_unlock_irq (&css_set_lock);
Signature · 1 line
2.30.2
Quoted 7 lines · Roman Gushchin
After the introduction of the cgroup.kill there is only one call site of
cgroup_task_freeze()left:cgroup_exit().cgroup_task_freeze()is currently takingrcu_read_lock()to read task's cgroup flags, but because it's always called withcss_set_locklocked, the rcu protection is excessive.
Quoted 5 lines
Simplify the code by inlining
cgroup_task_freeze().v2: fix build
Signed-off-by Roman Gushchin <[email protected]>
kernel test robot
build botThank you for the patch! Yet something to improve:
Hi Roman,
Thank you for the patch! Yet something to improve:
[auto build test ERROR on v5.13-rc1]
[also build test ERROR on next-20210510]
[cannot apply to cgroup/for-next]
[If your patch is applied to the wrong git tree, kindly drop us a note. And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch]
url: https://github.com/0day-ci/linux/commits/Roman-Gushchin/cgroup-inline-cgroup_task_freeze/20210511-054016 base: 6efb943b8616ec53a5e444193dccf1af9ad627b5 config: s390-randconfig-r014-20210510 (attached as .config) compiler: clang version 13.0.0 (https://github.com/llvm/llvm-project a0fed635fe1701470062495a6ffee1c608f3f1bc)
reproduce (this is a W=1 build):
wget https://raw.githubusercontent.com/intel/lkp-tests/master/sbin/make.cross -O ~/bin/make.cross chmod +x ~/bin/make.cross
# install s390 cross compiling tool for clang build
# apt-get install binutils-s390x-linux-gnu
# https://github.com/0day-ci/linux/commit/e291ca6f1be456048725ece6ad45384eb60199bc
git remote add linux-review https://github.com/0day-ci/linux
git fetch --no-tags linux-review Roman-Gushchin/cgroup-inline-cgroup_task_freeze/20210511-054016 git checkout e291ca6f1be456048725ece6ad45384eb60199bc
# save the attached .config to linux build tree
COMPILER_INSTALL_PATH=$HOME/0day COMPILER=clang make.cross W=1 ARCH=s390
If you fix the issue, kindly add following tag as appropriate
All errors (new ones prefixed by >>):
In file included from kernel/cgroup/cgroup.c:35:
In file included from include/linux/init_task.h:18:
In file included from include/net/net_namespace.h:38:
In file included from include/linux/skbuff.h:31:
In file included from include/linux/dma-mapping.h:10:
In file included from include/linux/scatterlist.h:9:
In file included from arch/s390/include/asm/io.h:75:
include/asm-generic/io.h:464:31: warning: performing pointer arithmetic on a null pointer has undefined behavior [-Wnull-pointer-arithmetic]
val = __raw_readb(PCI_IOBASE + addr);
~~~~~~~~~~ ^
include/asm-generic/io.h:477:61: warning: performing pointer arithmetic on a null pointer has undefined behavior [-Wnull-pointer-arithmetic]
val = __le16_to_cpu((__le16 __force)__raw_readw(PCI_IOBASE + addr));
~~~~~~~~~~ ^
include/uapi/linux/byteorder/big_endian.h:36:59: note: expanded from macro '__le16_to_cpu'
#define __le16_to_cpu(x) __swab16((__force __u16)(__le16)(x))
^
include/uapi/linux/swab.h:102:54: note: expanded from macro '__swab16'
#define __swab16(x) (__u16)__builtin_bswap16((__u16)(x))
^
In file included from kernel/cgroup/cgroup.c:35:
In file included from include/linux/init_task.h:18:
In file included from include/net/net_namespace.h:38:
In file included from include/linux/skbuff.h:31:
In file included from include/linux/dma-mapping.h:10:
In file included from include/linux/scatterlist.h:9:
In file included from arch/s390/include/asm/io.h:75:
include/asm-generic/io.h:490:61: warning: performing pointer arithmetic on a null pointer has undefined behavior [-Wnull-pointer-arithmetic]
val = __le32_to_cpu((__le32 __force)__raw_readl(PCI_IOBASE + addr));
~~~~~~~~~~ ^
include/uapi/linux/byteorder/big_endian.h:34:59: note: expanded from macro '__le32_to_cpu'
#define __le32_to_cpu(x) __swab32((__force __u32)(__le32)(x))
^
include/uapi/linux/swab.h:115:54: note: expanded from macro '__swab32'
#define __swab32(x) (__u32)__builtin_bswap32((__u32)(x))
^
In file included from kernel/cgroup/cgroup.c:35:
In file included from include/linux/init_task.h:18:
In file included from include/net/net_namespace.h:38:
In file included from include/linux/skbuff.h:31:
In file included from include/linux/dma-mapping.h:10:
In file included from include/linux/scatterlist.h:9:
In file included from arch/s390/include/asm/io.h:75:
include/asm-generic/io.h:501:33: warning: performing pointer arithmetic on a null pointer has undefined behavior [-Wnull-pointer-arithmetic]
__raw_writeb(value, PCI_IOBASE + addr);
~~~~~~~~~~ ^
include/asm-generic/io.h:511:59: warning: performing pointer arithmetic on a null pointer has undefined behavior [-Wnull-pointer-arithmetic]
__raw_writew((u16 __force)cpu_to_le16(value), PCI_IOBASE + addr);
~~~~~~~~~~ ^
include/asm-generic/io.h:521:59: warning: performing pointer arithmetic on a null pointer has undefined behavior [-Wnull-pointer-arithmetic]
__raw_writel((u32 __force)cpu_to_le32(value), PCI_IOBASE + addr);
~~~~~~~~~~ ^
include/asm-generic/io.h:609:20: warning: performing pointer arithmetic on a null pointer has undefined behavior [-Wnull-pointer-arithmetic]
readsb(PCI_IOBASE + addr, buffer, count);
~~~~~~~~~~ ^
include/asm-generic/io.h:617:20: warning: performing pointer arithmetic on a null pointer has undefined behavior [-Wnull-pointer-arithmetic]
readsw(PCI_IOBASE + addr, buffer, count);
~~~~~~~~~~ ^
include/asm-generic/io.h:625:20: warning: performing pointer arithmetic on a null pointer has undefined behavior [-Wnull-pointer-arithmetic]
readsl(PCI_IOBASE + addr, buffer, count);
~~~~~~~~~~ ^
include/asm-generic/io.h:634:21: warning: performing pointer arithmetic on a null pointer has undefined behavior [-Wnull-pointer-arithmetic]
writesb(PCI_IOBASE + addr, buffer, count);
~~~~~~~~~~ ^
include/asm-generic/io.h:643:21: warning: performing pointer arithmetic on a null pointer has undefined behavior [-Wnull-pointer-arithmetic]
writesw(PCI_IOBASE + addr, buffer, count);
~~~~~~~~~~ ^
include/asm-generic/io.h:652:21: warning: performing pointer arithmetic on a null pointer has undefined behavior [-Wnull-pointer-arithmetic]
writesl(PCI_IOBASE + addr, buffer, count);
~~~~~~~~~~ ^
>> kernel/cgroup/cgroup.c:6112:15: error: implicit declaration of function 'cgroup_task_freeze' [-Werror,-Wimplicit-function-declaration]
if (unlikely(cgroup_task_freeze(child))) {
^
kernel/cgroup/cgroup.c:6112:15: note: did you mean 'cgroup_task_frozen'?
include/linux/cgroup.h:909:20: note: 'cgroup_task_frozen' declared here
static inline bool cgroup_task_frozen(struct task_struct *task)
^12 warnings and 1 error generated.
vim +/cgroup_task_freeze +6112 kernel/cgroup/cgroup.c
7e47682ea555e7 kernel/cgroup.c Aleksa Sarai 2015-06-09 6076
817929ec274bcf kernel/cgroup.c Paul Menage 2007-10-18 6077 /**
5a5cf5cb30d781 kernel/cgroup/cgroup.c Christian Brauner 2020-02-05 6078 * cgroup_post_fork - finalize cgroup setup for the child process
5a5cf5cb30d781 kernel/cgroup/cgroup.c Christian Brauner 2020-02-05 6079 * @child: the child process
a043e3b2c63445 kernel/cgroup.c Li Zefan 2008-02-23 6080 *
5a5cf5cb30d781 kernel/cgroup/cgroup.c Christian Brauner 2020-02-05 6081 * Attach the child process to its css_set calling the subsystem fork()
5a5cf5cb30d781 kernel/cgroup/cgroup.c Christian Brauner 2020-02-05 6082 * callbacks.
a043e3b2c63445 kernel/cgroup.c Li Zefan 2008-02-23 6083 */
ef2c41cf38a755 kernel/cgroup/cgroup.c Christian Brauner 2020-02-05 6084 void cgroup_post_fork(struct task_struct *child,
ef2c41cf38a755 kernel/cgroup/cgroup.c Christian Brauner 2020-02-05 6085 struct kernel_clone_args *kargs)
ef2c41cf38a755 kernel/cgroup/cgroup.c Christian Brauner 2020-02-05 6086 __releases(&cgroup_threadgroup_rwsem) __releases(&cgroup_mutex)
817929ec274bcf kernel/cgroup.c Paul Menage 2007-10-18 6087 {
30159ec7a9db7f kernel/cgroup.c Tejun Heo 2013-06-25 6088 struct cgroup_subsys *ss;
eaf797abc53b0a kernel/cgroup.c Tejun Heo 2014-02-25 6089 struct css_set *cset;
5153faac18d293 kernel/cgroup/cgroup.c Tejun Heo 2019-10-24 6090 int i;
eaf797abc53b0a kernel/cgroup.c Tejun Heo 2014-02-25 6091
ef2c41cf38a755 kernel/cgroup/cgroup.c Christian Brauner 2020-02-05 6092 cset = kargs->cset;
ef2c41cf38a755 kernel/cgroup/cgroup.c Christian Brauner 2020-02-05 6093 kargs->cset = NULL;
ef2c41cf38a755 kernel/cgroup/cgroup.c Christian Brauner 2020-02-05 6094
82d6489d0fed2e kernel/cgroup.c Daniel Bristot de Oliveira 2016-06-22 6095 spin_lock_irq(&css_set_lock);
5153faac18d293 kernel/cgroup/cgroup.c Tejun Heo 2019-10-24 6096
0cd9d33ace336b kernel/cgroup/cgroup.c Tejun Heo 2020-01-30 6097 /* init tasks are special, only link regular threads */
0cd9d33ace336b kernel/cgroup/cgroup.c Tejun Heo 2020-01-30 6098 if (likely(child->pid)) {
5153faac18d293 kernel/cgroup/cgroup.c Tejun Heo 2019-10-24 6099 WARN_ON_ONCE(!list_empty(&child->cg_list));
73a7242a06ff99 kernel/cgroup/cgroup.c Waiman Long 2017-06-13 6100 cset->nr_tasks++;
f6d7d049c17a29 kernel/cgroup.c Tejun Heo 2015-10-15 6101 css_set_move_task(child, NULL, cset, false);
ef2c41cf38a755 kernel/cgroup/cgroup.c Christian Brauner 2020-02-05 6102 } else {
ef2c41cf38a755 kernel/cgroup/cgroup.c Christian Brauner 2020-02-05 6103 put_css_set(cset);
ef2c41cf38a755 kernel/cgroup/cgroup.c Christian Brauner 2020-02-05 6104 cset = NULL;
0cd9d33ace336b kernel/cgroup/cgroup.c Tejun Heo 2020-01-30 6105 }
76f969e8948d82 kernel/cgroup/cgroup.c Roman Gushchin 2019-04-19 6106
76f969e8948d82 kernel/cgroup/cgroup.c Roman Gushchin 2019-04-19 6107 /*
5153faac18d293 kernel/cgroup/cgroup.c Tejun Heo 2019-10-24 6108 * If the cgroup has to be frozen, the new task has too. Let's set
5153faac18d293 kernel/cgroup/cgroup.c Tejun Heo 2019-10-24 6109 * the JOBCTL_TRAP_FREEZE jobctl bit to get the task into the
5153faac18d293 kernel/cgroup/cgroup.c Tejun Heo 2019-10-24 6110 * frozen state.
76f969e8948d82 kernel/cgroup/cgroup.c Roman Gushchin 2019-04-19 6111 */
76f969e8948d82 kernel/cgroup/cgroup.c Roman Gushchin 2019-04-19 @6112 if (unlikely(cgroup_task_freeze(child))) {
76f969e8948d82 kernel/cgroup/cgroup.c Roman Gushchin 2019-04-19 6113 spin_lock(&child->sighand->siglock);
76f969e8948d82 kernel/cgroup/cgroup.c Roman Gushchin 2019-04-19 6114 WARN_ON_ONCE(child->frozen);
76f969e8948d82 kernel/cgroup/cgroup.c Roman Gushchin 2019-04-19 6115 child->jobctl |= JOBCTL_TRAP_FREEZE;
76f969e8948d82 kernel/cgroup/cgroup.c Roman Gushchin 2019-04-19 6116 spin_unlock(&child->sighand->siglock);
76f969e8948d82 kernel/cgroup/cgroup.c Roman Gushchin 2019-04-19 6117
76f969e8948d82 kernel/cgroup/cgroup.c Roman Gushchin 2019-04-19 6118 /*
76f969e8948d82 kernel/cgroup/cgroup.c Roman Gushchin 2019-04-19 6119 * Calling cgroup_update_frozen() isn't required here,
5153faac18d293 kernel/cgroup/cgroup.c Tejun Heo 2019-10-24 6120 * because it will be called anyway a bit later from
5153faac18d293 kernel/cgroup/cgroup.c Tejun Heo 2019-10-24 6121 * do_freezer_trap(). So we avoid cgroup's transient switch
5153faac18d293 kernel/cgroup/cgroup.c Tejun Heo 2019-10-24 6122 * from the frozen state and back.
76f969e8948d82 kernel/cgroup/cgroup.c Roman Gushchin 2019-04-19 6123 */
76f969e8948d82 kernel/cgroup/cgroup.c Roman Gushchin 2019-04-19 6124 }
76f969e8948d82 kernel/cgroup/cgroup.c Roman Gushchin 2019-04-19 6125
82d6489d0fed2e kernel/cgroup.c Daniel Bristot de Oliveira 2016-06-22 6126 spin_unlock_irq(&css_set_lock);
5edee61edeaaeb kernel/cgroup.c Tejun Heo 2012-10-16 6127
5edee61edeaaeb kernel/cgroup.c Tejun Heo 2012-10-16 6128 /*
5edee61edeaaeb kernel/cgroup.c Tejun Heo 2012-10-16 6129 * Call ss->fork(). This must happen after @child is linked on
5edee61edeaaeb kernel/cgroup.c Tejun Heo 2012-10-16 6130 * css_set; otherwise, @child might change state between ->fork()
5edee61edeaaeb kernel/cgroup.c Tejun Heo 2012-10-16 6131 * and addition to css_set.
5edee61edeaaeb kernel/cgroup.c Tejun Heo 2012-10-16 6132 */
b4e0eeafba61b1 kernel/cgroup.c Tejun Heo 2016-02-22 6133 do_each_subsys_mask(ss, i, have_fork_callback) {
b53202e6308939 kernel/cgroup.c Oleg Nesterov 2015-12-03 6134 ss->fork(child);
b4e0eeafba61b1 kernel/cgroup.c Tejun Heo 2016-02-22 6135 } while_each_subsys_mask();
5a5cf5cb30d781 kernel/cgroup/cgroup.c Christian Brauner 2020-02-05 6136
ef2c41cf38a755 kernel/cgroup/cgroup.c Christian Brauner 2020-02-05 6137 /* Make the new cset the root_cset of the new cgroup namespace. */
ef2c41cf38a755 kernel/cgroup/cgroup.c Christian Brauner 2020-02-05 6138 if (kargs->flags & CLONE_NEWCGROUP) {
ef2c41cf38a755 kernel/cgroup/cgroup.c Christian Brauner 2020-02-05 6139 struct css_set *rcset = child->nsproxy->cgroup_ns->root_cset;
ef2c41cf38a755 kernel/cgroup/cgroup.c Christian Brauner 2020-02-05 6140
ef2c41cf38a755 kernel/cgroup/cgroup.c Christian Brauner 2020-02-05 6141 get_css_set(cset);
ef2c41cf38a755 kernel/cgroup/cgroup.c Christian Brauner 2020-02-05 6142 child->nsproxy->cgroup_ns->root_cset = cset;
ef2c41cf38a755 kernel/cgroup/cgroup.c Christian Brauner 2020-02-05 6143 put_css_set(rcset);
ef2c41cf38a755 kernel/cgroup/cgroup.c Christian Brauner 2020-02-05 6144 }
ef2c41cf38a755 kernel/cgroup/cgroup.c Christian Brauner 2020-02-05 6145
ef2c41cf38a755 kernel/cgroup/cgroup.c Christian Brauner 2020-02-05 6146 cgroup_css_set_put_fork(kargs);
5edee61edeaaeb kernel/cgroup.c Tejun Heo 2012-10-16 6147 }
5edee61edeaaeb kernel/cgroup.c Tejun Heo 2012-10-16 6148 ---
0-DAY CI Kernel Test Service, Intel Corporation
https://lists.01.org/hyperkitty/list/kbuild-all(a)lists.01.org