1. 19 9月, 2015 2 次提交
    • T
      cgroup: replace cftype->mode with CFTYPE_WORLD_WRITABLE · 7dbdb199
      Tejun Heo 提交于
      cftype->mode allows controllers to give arbitrary permissions to
      interface knobs.  Except for "cgroup.event_control", the existing uses
      are spurious.
      
      * Some explicitly specify S_IRUGO | S_IWUSR even though that's the
        default.
      
      * "cpuset.memory_pressure" specifies S_IRUGO while also setting a
        write callback which returns -EACCES.  All it needs to do is simply
        not setting a write callback.
      
      "cgroup.event_control" uses cftype->mode to make the file
      world-writable.  It's a misdesigned interface and we don't want
      controllers to be tweaking interface file permissions in general.
      This patch removes cftype->mode and all its spurious uses and
      implements CFTYPE_WORLD_WRITABLE for "cgroup.event_control" which is
      marked as compatibility-only.
      Signed-off-by: NTejun Heo <tj@kernel.org>
      Cc: Li Zefan <lizefan@huawei.com>
      Cc: Johannes Weiner <hannes@cmpxchg.org>
      7dbdb199
    • T
      cgroup: replace "cgroup.populated" with "cgroup.events" · 4a07c222
      Tejun Heo 提交于
      memcg already uses "memory.events" for event reporting and other
      controllers may need event reporting too.  Let's standardize on
      "$SUBSYS.events" interface file for reporting events which don't
      happen too frequently and thus can share event notification.
      
      "cgroup.populated" is replaced with "populated" field in
      "cgroup.events" and documentation is updated accordingly.
      Signed-off-by: NTejun Heo <tj@kernel.org>
      Cc: Li Zefan <lizefan@huawei.com>
      Cc: Johannes Weiner <hannes@cmpxchg.org>
      4a07c222
  2. 18 9月, 2015 1 次提交
    • T
      cgroup: replace cgroup_subsys->disabled tests with cgroup_subsys_enabled() · fc5ed1e9
      Tejun Heo 提交于
      Replace cgroup_subsys->disabled tests in controllers with
      cgroup_subsys_enabled().  cgroup_subsys_enabled() requires literal
      subsys name as its parameter and thus can't be used for cgroup core
      which iterates through controllers.  For cgroup core, introduce and
      use cgroup_ssid_enabled() which uses slower static_key_enabled() test
      and can be indexed by subsys ID.
      
      This leaves cgroup_subsys->disabled unused.  Removed.
      Signed-off-by: NTejun Heo <tj@kernel.org>
      Acked-by: NZefan Li <lizefan@huawei.com>
      Cc: Johannes Weiner <hannes@cmpxchg.org>
      Cc: Michal Hocko <mhocko@kernel.org>
      fc5ed1e9
  3. 17 9月, 2015 1 次提交
    • T
      sched, cgroup: replace signal_struct->group_rwsem with a global percpu_rwsem · 1ed13287
      Tejun Heo 提交于
      Note: This commit was originally committed as d59cfc09 but got
            reverted by 0c986253 due to the performance regression from
            the percpu_rwsem write down/up operations added to cgroup task
            migration path.  percpu_rwsem changes which alleviate the
            performance issue are pending for v4.4-rc1 merge window.
            Re-apply.
      
      The cgroup side of threadgroup locking uses signal_struct->group_rwsem
      to synchronize against threadgroup changes.  This per-process rwsem
      adds small overhead to thread creation, exit and exec paths, forces
      cgroup code paths to do lock-verify-unlock-retry dance in a couple
      places and makes it impossible to atomically perform operations across
      multiple processes.
      
      This patch replaces signal_struct->group_rwsem with a global
      percpu_rwsem cgroup_threadgroup_rwsem which is cheaper on the reader
      side and contained in cgroups proper.  This patch converts one-to-one.
      
      This does make writer side heavier and lower the granularity; however,
      cgroup process migration is a fairly cold path, we do want to optimize
      thread operations over it and cgroup migration operations don't take
      enough time for the lower granularity to matter.
      Signed-off-by: NTejun Heo <tj@kernel.org>
      Link: http://lkml.kernel.org/g/55F8097A.7000206@de.ibm.com
      Cc: Ingo Molnar <mingo@redhat.com>
      Cc: Peter Zijlstra <peterz@infradead.org>
      1ed13287
  4. 16 9月, 2015 1 次提交
    • T
      Revert "sched, cgroup: replace signal_struct->group_rwsem with a global percpu_rwsem" · 0c986253
      Tejun Heo 提交于
      This reverts commit d59cfc09.
      
      d59cfc09 ("sched, cgroup: replace signal_struct->group_rwsem with
      a global percpu_rwsem") and b5ba75b5 ("cgroup: simplify
      threadgroup locking") changed how cgroup synchronizes against task
      fork and exits so that it uses global percpu_rwsem instead of
      per-process rwsem; unfortunately, the write [un]lock paths of
      percpu_rwsem always involve synchronize_rcu_expedited() which turned
      out to be too expensive.
      
      Improvements for percpu_rwsem are scheduled to be merged in the coming
      v4.4-rc1 merge window which alleviates this issue.  For now, revert
      the two commits to restore per-process rwsem.  They will be re-applied
      for the v4.4-rc1 merge window.
      Signed-off-by: NTejun Heo <tj@kernel.org>
      Link: http://lkml.kernel.org/g/55F8097A.7000206@de.ibm.comReported-by: NChristian Borntraeger <borntraeger@de.ibm.com>
      Cc: Oleg Nesterov <oleg@redhat.com>
      Cc: "Paul E. McKenney" <paulmck@linux.vnet.ibm.com>
      Cc: Peter Zijlstra <peterz@infradead.org>
      Cc: Paolo Bonzini <pbonzini@redhat.com>
      Cc: stable@vger.kernel.org # v4.2+
      0c986253
  5. 19 8月, 2015 1 次提交
    • T
      cgroup: introduce cgroup_subsys->legacy_name · 3e1d2eed
      Tejun Heo 提交于
      This allows cgroup subsystems to use a different name on the unified
      hierarchy.  cgroup_subsys->name is used on the unified hierarchy,
      ->legacy_name elsewhere.  If ->legacy_name is not explicitly set, it's
      automatically set to ->name and the userland visible behavior remains
      unchanged.
      
      v2: Make parse_cgroupfs_options() only consider ->legacy_name as mount
          options are used only on legacy hierarchies.  Suggested by Li
          Zefan.
      Signed-off-by: NTejun Heo <tj@kernel.org>
      Acked-by: NLi Zefan <lizefan@huawei.com>
      Cc: Johannes Weiner <hannes@cmpxchg.org>
      Cc: cgroups@vger.kernel.org
      3e1d2eed
  6. 12 8月, 2015 1 次提交
  7. 15 7月, 2015 1 次提交
    • A
      cgroup: allow a cgroup subsystem to reject a fork · 7e47682e
      Aleksa Sarai 提交于
      Add a new cgroup subsystem callback can_fork that conditionally
      states whether or not the fork is accepted or rejected by a cgroup
      policy. In addition, add a cancel_fork callback so that if an error
      occurs later in the forking process, any state modified by can_fork can
      be reverted.
      
      Allow for a private opaque pointer to be passed from cgroup_can_fork to
      cgroup_post_fork, allowing for the fork state to be stored by each
      subsystem separately.
      
      Also add a tagging system for cgroup_subsys.h to allow for CGROUP_<TAG>
      enumerations to be be defined and used. In addition, explicitly add a
      CGROUP_CANFORK_COUNT macro to make arrays easier to define.
      
      This is in preparation for implementing the pids cgroup subsystem.
      Signed-off-by: NAleksa Sarai <cyphar@cyphar.com>
      Signed-off-by: NTejun Heo <tj@kernel.org>
      7e47682e
  8. 19 6月, 2015 1 次提交
    • T
      cgroup: require write perm on common ancestor when moving processes on the default hierarchy · 187fe840
      Tejun Heo 提交于
      On traditional hierarchies, if a task has write access to "tasks" or
      "cgroup.procs" file of a cgroup and its euid agrees with the target,
      it can move the target to the cgroup; however, consider the following
      scenario.  The owner of each cgroup is in the parentheses.
      
       R (root) - 0 (root) - 00 (user1) - 000 (user1)
                |                       \ 001 (user1)
                \ 1 (root) - 10 (user1)
      
      The subtrees of 00 and 10 are delegated to user1; however, while both
      subtrees may belong to the same user, it is clear that the two
      subtrees are to be isolated - they're under completely separate
      resource limits imposed by 0 and 1, respectively.  Note that 0 and 1
      aren't strictly necessary but added to ease illustrating the issue.
      
      If user1 is allowed to move processes between the two subtrees, the
      intention of the hierarchy - keeping a given group of processes under
      a subtree with certain resource restrictions while delegating
      management of the subtree - can be circumvented by user1.
      
      This happens because migration permission check doesn't consider the
      hierarchical nature of cgroups.  To fix the issue, this patch adds an
      extra permission requirement when userland tries to migrate a process
      in the default hierarchy - the issuing task must have write access to
      the common ancestor of "cgroup.procs" file of the ancestor in addition
      to the destination's.
      
      Conceptually, the issuer must be able to move the target process from
      the source cgroup to the common ancestor of source and destination
      cgroups and then to the destination.  As long as delegation is done in
      a proper top-down way, this guarantees that a delegatee can't smuggle
      processes across disjoint delegation domains.
      
      The next patch will add documentation on the delegation model on the
      default hierarchy.
      
      v2: Fixed missing !ret test.  Spotted by Li Zefan.
      Signed-off-by: NTejun Heo <tj@kernel.org>
      Acked-by: NJohannes Weiner <hannes@cmpxchg.org>
      Cc: Li Zefan <lizefan@huawei.com>
      187fe840
  9. 08 6月, 2015 1 次提交
    • A
      cgroup: use bitmask to filter for_each_subsys · cb4a3167
      Aleksa Sarai 提交于
      Add a new macro for_each_subsys_which that allows all enabled cgroup
      subsystems to be filtered by a bitmask, such that mask & (1 << ssid)
      determines if the subsystem is to be processed in the loop body (where
      ssid is the unique id of the subsystem).
      
      Also replace the need_forkexit_callback with two separate bitmasks for
      each callback to make (ss->{fork,exit}) checks unnecessary.
      
      tj: add a short comment for "if (!CGROUP_SUBSYS_COUNT)".
      Signed-off-by: NAleksa Sarai <cyphar@cyphar.com>
      cb4a3167
  10. 29 5月, 2015 1 次提交
    • A
      cgroup: add seq_file forward declaration for struct cftype · c80ef9e0
      Arnd Bergmann 提交于
      Recent header file changes for cgroup caused lots of warnings
      about a missing struct seq_file form declaration for every
      inclusion of include/linux/cgroup-defs.h.
      
      As some files are built with -Werror, this leads to build
      failure like:
      
                       from /git/arm-soc/drivers/gpu/drm/tilcdc/tilcdc_crtc.c:18:
      /git/arm-soc/include/linux/cgroup-defs.h:354:25: error: 'struct seq_file' declared inside parameter list [-Werror]
      cc1: all warnings being treated as errors
      make[6]: *** [drivers/gpu/drm/tilcdc/tilcdc_crtc.o] Error 1
      
      This patch adds the declaration, which resolves both the
      warnings and the drm failure.
      
      tj: Moved it where other type declarations are.
      Signed-off-by: NArnd Bergmann <arnd@arndb.de>
      Fixes: b4a04ab7 ("cgroup: separate out include/linux/cgroup-defs.h")
      Signed-off-by: NTejun Heo <tj@kernel.org>
      c80ef9e0
  11. 27 5月, 2015 2 次提交
    • T
      sched, cgroup: replace signal_struct->group_rwsem with a global percpu_rwsem · d59cfc09
      Tejun Heo 提交于
      The cgroup side of threadgroup locking uses signal_struct->group_rwsem
      to synchronize against threadgroup changes.  This per-process rwsem
      adds small overhead to thread creation, exit and exec paths, forces
      cgroup code paths to do lock-verify-unlock-retry dance in a couple
      places and makes it impossible to atomically perform operations across
      multiple processes.
      
      This patch replaces signal_struct->group_rwsem with a global
      percpu_rwsem cgroup_threadgroup_rwsem which is cheaper on the reader
      side and contained in cgroups proper.  This patch converts one-to-one.
      
      This does make writer side heavier and lower the granularity; however,
      cgroup process migration is a fairly cold path, we do want to optimize
      thread operations over it and cgroup migration operations don't take
      enough time for the lower granularity to matter.
      Signed-off-by: NTejun Heo <tj@kernel.org>
      Cc: Ingo Molnar <mingo@redhat.com>
      Cc: Peter Zijlstra <peterz@infradead.org>
      d59cfc09
    • T
      sched, cgroup: reorganize threadgroup locking · 7d7efec3
      Tejun Heo 提交于
      threadgroup_change_begin/end() are used to mark the beginning and end
      of threadgroup modifying operations to allow code paths which require
      a threadgroup to stay stable across blocking operations to synchronize
      against those sections using threadgroup_lock/unlock().
      
      It's currently implemented as a general mechanism in sched.h using
      per-signal_struct rwsem; however, this never grew non-cgroup use cases
      and becomes noop if !CONFIG_CGROUPS.  It turns out that cgroups is
      gonna be better served with a different sycnrhonization scheme and is
      a bit silly to keep cgroups specific details as a general mechanism.
      
      What's general here is identifying the places where threadgroups are
      modified.  This patch restructures threadgroup locking so that
      threadgroup_change_begin/end() become a place where subsystems which
      need to sycnhronize against threadgroup changes can hook into.
      
      cgroup_threadgroup_change_begin/end() which operate on the
      per-signal_struct rwsem are created and threadgroup_lock/unlock() are
      moved to cgroup.c and made static.
      
      This is pure reorganization which doesn't cause any functional
      changes.
      Signed-off-by: NTejun Heo <tj@kernel.org>
      Cc: Ingo Molnar <mingo@redhat.com>
      Cc: Peter Zijlstra <peterz@infradead.org>
      7d7efec3
  12. 19 5月, 2015 1 次提交
    • T
      cgroup: separate out include/linux/cgroup-defs.h · b4a04ab7
      Tejun Heo 提交于
      From 2d728f74bfc071df06773e2fd7577dd5dab6425d Mon Sep 17 00:00:00 2001
      From: Tejun Heo <tj@kernel.org>
      Date: Wed, 13 May 2015 15:37:01 -0400
      
      This patch separates out cgroup-defs.h from cgroup.h which has grown a
      lot of dependencies.  cgroup-defs.h currently only contains constant
      and type definitions and can be used to break circular include
      dependency.  While moving, definitions are reordered so that
      cgroup-defs.h has consistent logical structure.
      
      This patch is pure reorganization.
      Signed-off-by: NTejun Heo <tj@kernel.org>
      b4a04ab7