Re: [PATCH V1 1/2] mm/damon/dbgfs: Put "paddr" check into damon_pa_check() func
From: SeongJae Park
Date: Thu Jan 20 2022 - 12:47:25 EST
Hi Xin,
On Fri, 21 Jan 2022 00:04:27 +0800 Xin Hao <xhao@xxxxxxxxxxxxxxxxx> wrote:
> The purpose of putting "paddr" check into damon_pa_check() func
> is to better solve "DAMON_DBGFS" dependency on both "DAMON_VADDR"
> and "DAMON_PADDR".
Syntax of "paddr" is dbgfs's own. I don't think handling it in paddr is a
right thing to do.
Thanks,
SJ
>
> Signed-off-by: Xin Hao <xhao@xxxxxxxxxxxxxxxxx>
> ---
> include/linux/damon.h | 1 +
> mm/damon/dbgfs.c | 2 +-
> mm/damon/paddr.c | 8 ++++++++
> 3 files changed, 10 insertions(+), 1 deletion(-)
>
> diff --git a/include/linux/damon.h b/include/linux/damon.h
> index 5e1e3a128b77..794b5f453662 100644
> --- a/include/linux/damon.h
> +++ b/include/linux/damon.h
> @@ -504,6 +504,7 @@ void damon_va_set_primitives(struct damon_ctx *ctx);
> #endif /* CONFIG_DAMON_VADDR */
>
> #ifdef CONFIG_DAMON_PADDR
> +bool damon_pa_check(char *buf, size_t count);
> bool damon_pa_target_valid(void *t);
> void damon_pa_set_primitives(struct damon_ctx *ctx);
> #endif /* CONFIG_DAMON_PADDR */
> diff --git a/mm/damon/dbgfs.c b/mm/damon/dbgfs.c
> index 5b899601e56c..cdb9c1e2ab29 100644
> --- a/mm/damon/dbgfs.c
> +++ b/mm/damon/dbgfs.c
> @@ -374,7 +374,7 @@ static ssize_t dbgfs_target_ids_write(struct file *file,
> if (IS_ERR(kbuf))
> return PTR_ERR(kbuf);
>
> - if (!strncmp(kbuf, "paddr\n", count)) {
> + if (damon_pa_check(kbuf, count)) {
> id_is_pid = false;
> /* target id is meaningless here, but we set it just for fun */
> scnprintf(kbuf, count, "42 ");
> diff --git a/mm/damon/paddr.c b/mm/damon/paddr.c
> index 5e8244f65a1a..14a6bf2a2adb 100644
> --- a/mm/damon/paddr.c
> +++ b/mm/damon/paddr.c
> @@ -208,6 +208,14 @@ static unsigned int damon_pa_check_accesses(struct damon_ctx *ctx)
> return max_nr_accesses;
> }
>
> +bool damon_pa_check(char *buf, size_t count)
> +{
> + if (!strncmp(buf, "paddr\n", count))
> + return true;
> +
> + return false;
> +}
> +
> bool damon_pa_target_valid(void *t)
> {
> return true;
> --
> 2.27.0
>
>