Skip to content

RFC mm/damon/sysfs: kobject_del() directories that users can create/remove

SeongJae Park damon linux-mm lkml stable 1 version In review

Get series with b4
b4 am [email protected]

Versions newest first

  1. v1 RFC Latest11 patches 2 repliesIn review

Changes from RFC v1 from the cover letter

- RFC v1: https://lore.kernel.org/[email protected]
- Add error path fixes.

Patches in v1 No applies recorded yet

#Subject and filesSizeRepliesApplied
1/11mm/damon/sysfs: kobject_del() target (normal), context and kdamond dirsmm/damon/sysfs.c+9 -21 reply
2/11mm/damon/sysfs: kobject_del() region and target (error) dirsmm/damon/sysfs.c+6 -20 replies
3/11mm/damon/sysfs-schemes: kobject_del() scheme dirsmm/damon/sysfs-schemes.c+1 -00 replies
4/11mm/damon/sysfs-schemes: kobject_del() scheme region dirsmm/damon/sysfs-schemes.c+1 -00 replies
5/11mm/damon/sysfs-schemes: kobject_del() scheme filter dirsmm/damon/sysfs-schemes.c+3 -10 replies
6/11mm/damon/sysfs-schemes: kobject_del() scheme quota goal dirsmm/damon/sysfs-schemes.c+3 -10 replies
7/11mm/damon/sysfs-schemes: kobject_del() scheme action destination dirsmm/damon/sysfs-schemes.c+3 -10 replies
8/11mm/damon/sysfs: kobject_del() probe dirsmm/damon/sysfs.c+1 -00 replies
9/11mm/damon/sysfs: kobject_del() probe filter dirsmm/damon/sysfs.c+3 -10 replies
10/11mm/damon/sysfs: kobject_del() probe dirs in probes_addd_dir error pathmm/damon/sysfs.c+1 -00 replies
11/11mm/damon/sysfs-schemes: kobject_del() region for populate_region errormm/damon/sysfs-schemes.c+3 -10 replies

Reviews trailers per patch

No Reviewed-by, Acked-by or Tested-by trailers for v1 yet.

Read the v1 thread

Cover letter [RFC PATCH v1.1 00/11] mm/damon/sysfs: kobject_del() directories that users can create/remove

DAMON sysfs interface allows users to create and remove arbitrary number of directories on sysfs, using a few files having 'nr_' prefix. For example, 'nr_kdamonds'. When the user writes a number 'N' to the files, directories having name starting from '0' to 'N - 1' are created in the same directory. The pre-existing number-named directories are removed before creating the new directories.

For the removal of the existing directories, DAMON sysfs interface use only kobject_put(). Because DAMON sysfs interface is the only kernel component that manages the directories, there is no problem in normal situations. However, if CONFIG_DEBUG_KOBJECT_RELEASE is enabled, the removal of dirs are delayed. Let's suppose a user writes a non-zero number to the 'nr_*' files while there are pre-existing number-named directories, on the config enabled kernel. DAMON sysfs interface decreases the reference counts of the existing directories and immediately creates new directories. Because the removal of the sysfs directories is delayed, it shows some pre-existing directories of the same names when it tries to create the new directories, and fails.

For example, the issue can be triggered like below:

    # grep DEBUG_KOBJECT_RELEASE /boot/config-$(uname -r)
    CONFIG_DEBUG_KOBJECT_RELEASE=y
    # ls
    nr_kdamonds
    # echo 1 > nr_kdamonds
    # echo 1 > nr_kdamonds
    bash: echo: write error: File exists
    # dmesg
    [...]
    [  300.880458] kobject: kobject_add_internal failed for 0 with -EEXIST, don't try to register things with the same name in the same directory.
    [...]

Some of the error handling paths of the directories also lack the kobject_del() call. If the user uses nr_* file right after the errors, similar issues can happen.

This doesn't cause catastrophic issues like kernel panics or memory corruptions. Users can work around by removing all directories first (write 0 to the nr_* files) and then create new directories after confirming the old directories are gone. But, this is definitely a bug that causes a bad user experience.

Fix the issues by calling kobject_del() before creating new directories.

Patches Sequence
================

There are a number of bugs of this class that introduced by eleven different commits. Group fnd order fixes based on the introducing commits.

Changes from RFC v1
- RFC v1: https://lore.kernel.org/[email protected]
- Add error path fixes.

SeongJae Park (11):
mm/damon/sysfs: kobject_del() target (normal), context and kdamond
dirs
mm/damon/sysfs: kobject_del() region and target (error) dirs mm/damon/sysfs-schemes: kobject_del() scheme dirs mm/damon/sysfs-schemes: kobject_del() scheme region dirs mm/damon/sysfs-schemes: kobject_del() scheme filter dirs mm/damon/sysfs-schemes: kobject_del() scheme quota goal dirs mm/damon/sysfs-schemes: kobject_del() scheme action destination dirs mm/damon/sysfs: kobject_del() probe dirs
mm/damon/sysfs: kobject_del() probe filter dirs mm/damon/sysfs: kobject_del() probe dirs in probes_addd_dir error path mm/damon/sysfs-schemes: kobject_del() region for populate_region error

 mm/damon/sysfs-schemes.c | 18 ++++++++++++++----
 mm/damon/sysfs.c         | 25 ++++++++++++++++++++-----
 2 files changed, 34 insertions(+), 9 deletions(-)

base-commit: c7d696ef153b9bea79d35140c7e9266fe9d3f7bb

Signature · 1 line
2.47.3