On Wed, 16 Dec 2020 10:42:09 +0100 SeongJae Park <[email protected]> wrote:

> From: SeongJae Park <[email protected]>
> 
> Some 'damon-dbgfs' users would want to monitor only a part of the entire
> virtual memory address space.  The framework users in the kernel space
> could use '->init_target_regions' callback or even set the regions
> inside the context struct as they want, but 'damon-dbgfs' users cannot.
> 
> For the reason, this commit introduces a new debugfs file,
> 'init_region'.  'damon-dbgfs' users can specify which initial monitoring
> target address regions they want by writing special input to the file.
> The input should describe each region in each line in below form:
> 
>     <pid> <start address> <end address>
> 
> Note that the regions will be updated to cover entire memory mapped
> regions after 'regions update interval'.  If you want the regions to not
> be updated after the initial setting, you could set the interval as a
> very long time, say, a few decades.
> 
> Signed-off-by: SeongJae Park <[email protected]>
> ---
>  mm/damon/dbgfs.c | 154 ++++++++++++++++++++++++++++++++++++++++++++++-
>  1 file changed, 151 insertions(+), 3 deletions(-)
> 
> diff --git a/mm/damon/dbgfs.c b/mm/damon/dbgfs.c
> index 06295c986dc3..2f1ec6ebd9f0 100644
> --- a/mm/damon/dbgfs.c
> +++ b/mm/damon/dbgfs.c
[...]
> +
> +static ssize_t dbgfs_init_regions_read(struct file *file, char __user *buf,
> +             size_t count, loff_t *ppos)
> +{
> +     struct damon_ctx *ctx = file->private_data;
> +     char *kbuf;
> +     ssize_t len;
> +
> +     kbuf = kmalloc(count, GFP_KERNEL);
> +     if (!kbuf)
> +             return -ENOMEM;
> +
> +     mutex_lock(&ctx->kdamond_lock);
> +     if (ctx->kdamond) {
> +             mutex_unlock(&ctx->kdamond_lock);
> +             return -EBUSY;

Coverity Static Analysis Security Testing (SAST) by Synopsys, Inc. found that
above return is missing deallocation of 'kbuf'.  I will fix this in the next
version.

> +     }
> +
> +     len = sprint_init_regions(ctx, kbuf, count);
> +     mutex_unlock(&ctx->kdamond_lock);
> +     if (len < 0)
> +             goto out;
> +     len = simple_read_from_buffer(buf, count, ppos, kbuf, len);
> +
> +out:
> +     kfree(kbuf);
> +     return len;
> +}


Thanks,
SeongJae Park
[...]

Reply via email to