|
|
Subscribe / Log in / New account

kernfs: Use RCU to access kernfs_node::{parent|name}.

From:  Sebastian Andrzej Siewior <bigeasy-AT-linutronix.de>
To:  cgroups-AT-vger.kernel.org, linux-kernel-AT-vger.kernel.org
Subject:  [PATCH v6 0/6] kernfs: Use RCU to access kernfs_node::{parent|name}.
Date:  Thu, 30 Jan 2025 15:02:01 +0100
Message-ID:  <20250130140207.1914339-1-bigeasy@linutronix.de>
Cc:  Michal Koutný <mkoutny-AT-suse.com>, "Paul E. McKenney" <paulmck-AT-kernel.org>, Boqun Feng <boqun.feng-AT-gmail.com>, Greg Kroah-Hartman <gregkh-AT-linuxfoundation.org>, Hillf Danton <hdanton-AT-sina.com>, Johannes Weiner <hannes-AT-cmpxchg.org>, Marco Elver <elver-AT-google.com>, Tejun Heo <tj-AT-kernel.org>, tglx-AT-linutronix.de, Sebastian Andrzej Siewior <bigeasy-AT-linutronix.de>
Archive-link:  Article

Hi,

This started as a bug report by Hillf Danton and aims to access
kernfs_node::{name|parent} with RCU to avoid the lock during
kernfs_path_from_node().

I've split the individual fixes in separate patches (#1 to #4). I've
also split the ::parent and ::name RCU conversation into a single patch
(#5 and #6).

v5…v6 https://lore.kernel.org/all/20250128084226.1499291-1-bige...
  - s/rdt_kn_get_name/rdt_kn_name/
  - s/rdt_get_kn_parent_priv/rdt_kn_parent_priv/
  - s/kn_get_priv/kn_priv/
  - The comment, that has been removed in kernfs_put(), is back.
  - Using rcu_access_pointer() in kernfs_activate_one() and kernfs_dir_pos()
    instead of kernfs_parent() where the pointer is not dereferenced but
    just compared.

v4…v5 https://lore.kernel.org/all/20250124174614.866884-1-bigea...
  - rdtgroup:
    - Add a comment to rdt_get_kn_parent_priv() regarding lifetime of
      parent.
    - Move individual rcu_dereference_check() invocations into
      rdt_kn_parent() with a comment on lifetime.
    - Use rcu_access_pointer() in kernfs_to_rdtgroup() instead
      rcu_dereference_check(, true)
  - s/kernfs_rcu_get_name/kernfs_rcu_name/
  - Move all rcu_dereference_check() within kernfs into kernfs_parent()
    and extend its checks to have all cases in one spot. Document why
    each case makes sense.
  - kernfs_notify_workfn(): Do unlocks in the reverse order of locks.
  - Add kernfs_root_flags() and use it in cgroup's kn_get_priv() to
    check the right KERNFS_ROOT_INVARIANT_PARENT flag.

v3: https://lore.kernel.org/all/20241121175250.EJbI7VMb@linut...
v2: https://lore.kernel.org/all/20241112155713.269214-1-bigea...
v1: https://lore.kernel.org/all/20241108222406.n5azgO98@linut...

Sebastian

Sebastian Andrzej Siewior (6):
  kernfs: Acquire kernfs_rwsem in kernfs_notify_workfn().
  kernfs: Acquire kernfs_rwsem in kernfs_get_parent_dentry().
  kernfs: Acquire kernfs_rwsem in kernfs_node_dentry().
  kernfs: Don't re-lock kernfs_root::kernfs_rwsem in
    kernfs_fop_readdir().
  kernfs: Use RCU to access kernfs_node::parent.
  kernfs: Use RCU to access kernfs_node::name.

 arch/x86/kernel/cpu/resctrl/internal.h    |   5 +
 arch/x86/kernel/cpu/resctrl/pseudo_lock.c |  14 +-
 arch/x86/kernel/cpu/resctrl/rdtgroup.c    |  73 +++++---
 fs/kernfs/dir.c                           | 211 +++++++++++++---------
 fs/kernfs/file.c                          |   6 +-
 fs/kernfs/kernfs-internal.h               |  37 +++-
 fs/kernfs/mount.c                         |  21 ++-
 fs/kernfs/symlink.c                       |  30 +--
 fs/sysfs/dir.c                            |   2 +-
 fs/sysfs/file.c                           |  24 ++-
 include/linux/kernfs.h                    |  14 +-
 kernel/cgroup/cgroup-v1.c                 |   2 +-
 kernel/cgroup/cgroup.c                    |  24 ++-
 security/selinux/hooks.c                  |   7 +-
 14 files changed, 307 insertions(+), 163 deletions(-)

-- 
2.47.2




Copyright © 2025, Eklektix, Inc.
Comments and public postings are copyrighted by their creators.
Linux is a registered trademark of Linus Torvalds