DAMON fixes
Subsystems (3)
SeongJae Park
maintainercover DAMON fixes
This patchset is a backport of DAMON fixes that merged in the mainline, for v5.15.x stable series.
SeongJae Park (2):
mm/damon/dbgfs: use '__GFP_NOWARN' for user-specified size buffer
allocation
mm/damon/dbgfs: fix missed use of damon_dbgfs_lock
mm/damon/dbgfs.c | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-)
Signature · 1 line
2.17.1
SeongJae Park
maintainerPATCH 1/2 mm/damon/dbgfs: use '__GFP_NOWARN' for user-specified size buffer allocation
commit db7a347b26fe05d2e8c115bb24dfd908d0252bc3 upstream.
Patch series "DAMON fixes".
This patch (of 2):
DAMON users can trigger below warning in '__alloc_pages()' by invoking write() to some DAMON debugfs files with arbitrarily high count argument, because DAMON debugfs interface allocates some buffers based on the user-specified 'count'.
if (unlikely(order >= MAX_ORDER)) {
WARN_ON_ONCE(!(gfp & __GFP_NOWARN));
return NULL;
}Because the DAMON debugfs interface code checks failure of the 'kmalloc()', this commit simply suppresses the warnings by adding '__GFP_NOWARN' flag.
--- mm/damon/dbgfs.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
mm/damon/dbgfs.c +2 -2
@@ -32,7 +32,7 @@ static char *user_input_str(const char __user *buf, size_t count, loff_t *ppos)if (*ppos)return ERR_PTR (-EINVAL ); - kbuf =kmalloc (count +1 ,GFP_KERNEL ); + kbuf =kmalloc (count +1 ,GFP_KERNEL | __GFP_NOWARN);if (!kbuf)return ERR_PTR (-ENOMEM );
@@ -247,7 +247,7 @@ static ssize_t dbgfs_kdamond_pid_read(struct file *file,char *kbuf;ssize_t len; - kbuf =kmalloc (count,GFP_KERNEL ); + kbuf =kmalloc (count,GFP_KERNEL | __GFP_NOWARN);if (!kbuf)return -ENOMEM ;
Signature · 1 line
2.17.1
SeongJae Park
maintainerPATCH 2/2 mm/damon/dbgfs: fix missed use of damon_dbgfs_lock
In reply to SeongJae Parkcommit d78f3853f831eee46c6dbe726debf3be9e9c0d05 upstream.
DAMON debugfs is supposed to protect dbgfs_ctxs, dbgfs_nr_ctxs, and dbgfs_dirs using damon_dbgfs_lock. However, some of the code is accessing the variables without the protection. This fixes it by protecting all such accesses.
--- mm/damon/dbgfs.c | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-)
mm/damon/dbgfs.c +8 -3
@@ -538,12 +538,14 @@ static ssize_t dbgfs_monitor_on_write(struct file *file,return -EINVAL ; } +mutex_lock (&damon_dbgfs_lock);if (!strncmp (kbuf,"on" , count)) err =damon_start (dbgfs_ctxs, dbgfs_nr_ctxs);else if (!strncmp (kbuf,"off" , count)) err =damon_stop (dbgfs_ctxs, dbgfs_nr_ctxs);else err = -EINVAL ; +mutex_unlock (&damon_dbgfs_lock);if (err) ret = err;
@@ -596,15 +598,16 @@ static int __init __damon_dbgfs_init(void)static int __init damon_dbgfs_init (void ) { -int rc; +int rc = -ENOMEM ; +mutex_lock (&damon_dbgfs_lock); dbgfs_ctxs =kmalloc (sizeof (*dbgfs_ctxs),GFP_KERNEL );if (!dbgfs_ctxs) -return -ENOMEM ; + goto out; dbgfs_ctxs[0 ] =dbgfs_new_ctx ();if (!dbgfs_ctxs[0 ]) {kfree (dbgfs_ctxs); -return -ENOMEM ; + goto out; } dbgfs_nr_ctxs =1 ;
@@ -615,6 +618,8 @@ static int __init damon_dbgfs_init(void)pr_err ("%s: dbgfs init failed\n" , __func__); } +out: +mutex_unlock (&damon_dbgfs_lock);return rc; }
Signature · 1 line
2.17.1
Greg KH
maintainerQuoted 14 lines · SeongJae Park
This patchset is a backport of DAMON fixes that merged in the mainline, for v5.15.x stable series.
SeongJae Park (2):
mm/damon/dbgfs: use '__GFP_NOWARN' for user-specified size buffer
allocation
mm/damon/dbgfs: fix missed use ofdamon_dbgfs_lockmm/damon/dbgfs.c | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-)Signature · 1 line
2.17.1
Now queued up, thanks for the backports.
greg k-h