Re: [PATCH 2/4] mm/damon/sysfs: check contexts->nr before clear_schemes_tried_regions

SeongJae Park
2026-03-20T15:51:25Z

On Fri, 20 Mar 2026 15:14:54 +0000 Josh Law <objecting@objecting.org> wrote:

>
>
> On 20 March 2026 14:47:40 GMT, SeongJae Park <sj@kernel.org> wrote:
> >On Fri, 20 Mar 2026 07:06:48 +0000 Josh Law <objecting@objecting.org> wrote:
> >
> >>
> >>
> >> On 20 March 2026 02:13:17 GMT, SeongJae Park <sj@kernel.org> wrote:
> >> >On Thu, 19 Mar 2026 15:57:40 +0000 Josh Law <objecting@objecting.org> wrote:
[...]
> >> >Not necessarily blocker of this patch, but seems all the issues are in a same
> >> >category. The third patch of this series is also fixing one of the category
> >> >bugs. How about fixing all at once by checking kdamond->contexts->nr at the
> >> >beginning of damon_sysfs_handle_cmd(), like below?
> >> >
> >> >--- a/mm/damon/sysfs.c
> >> >+++ b/mm/damon/sysfs.c
> >> >@@ -2404,6 +2404,9 @@ static int damon_sysfs_update_schemes_tried_regions(
> >> > static int damon_sysfs_handle_cmd(enum damon_sysfs_cmd cmd,
> >> > struct damon_sysfs_kdamond *kdamond)
> >> > {
> >> >+ if (cmd != DAMON_SYSFS_CMD_OFF && kdamond->contexts->nr != 1)
> >> >+ return -EINVAL;
> >> >+
> >> > switch (cmd) {
> >> > case DAMON_SYSFS_CMD_ON:
> >> > return damon_sysfs_turn_damon_on(kdamond);
> >> >
> >> >If we pick this, Fixes: would be deserve to the oldest buggy commit that
> >> >introduced the first bug of this category. It is indeed quite old.
> >> >
> >> >Fixes: 0ac32b8affb5 ("mm/damon/sysfs: support DAMOS stats")
> >> >Cc: <stable@vger.kernel.org> # 5.18.x
> >> >
> >> >
> >> >Thanks,
> >> >SJ
> >>
> >>
> >>
> >> Hello, did you give Reviewed by you? Or not..
> >
> >Are you meaning Reviewed-by: tag? If so, no, not yet. I want to get your
> >answer to above question first. Could you please answer?
> >
> >
> >Thanks,
> >SJ
> >
> >[...]
>
>
> Well, two is in the same catagory. But seperate fixes may be best. Because patch 3 dont call that function, so it may be screwy, i mean, if you want me to. Ill guard it. But its a bit on the hacky side

I agree there could be more cleaner way. But these fixes need to go to stable,
so I'd prefer a change that also easier to backport.

So, yes, I want to. Thank you for kindly accepting my suggestion.

Could you please re-post this series for the first and the fourth patches as
they are, after adding my Reviewed-by:, Fixes: and Cc: stable tags, and a patch
checking kdamond->contexts->nr at the beginning of damon_sysfs_handle_cmd() as
I suggested?

Thanks,
SJ …