Re: [RFC PATCH v1.1 00/11] mm/damon/sysfs: kobject_del() directories that users can create/remove
From: SeongJae Park
Date: Wed Jun 17 2026 - 20:49:09 EST
On Wed, 17 Jun 2026 07:47:54 -0700 SeongJae Park <sj@xxxxxxxxxx> wrote:
> 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.
Sashiko found [1] one more issue of the same class in
damon_sysfs_schemes_add_dirs(). I will fix it in the next spin.
[1] https://lore.kernel.org/20260618004428.82261-1-sj@xxxxxxxxxx
Thanks,
SJ
[...]