linux-mm.kvack.org archive mirror
 help / color / mirror / Atom feed
* [PATCH v3] mm/damon/core: fix commit_ops_filters by using correct nth function
@ 2025-08-10 12:42 Sang-Heon Jeon
  2025-08-10 12:56 ` Sang-Heon Jeon
  2025-08-10 16:37 ` SeongJae Park
  0 siblings, 2 replies; 3+ messages in thread
From: Sang-Heon Jeon @ 2025-08-10 12:42 UTC (permalink / raw)
  To: sj, honggyu.kim; +Cc: damon, linux-mm, Sang-Heon Jeon, stable

damos_commit_ops_filters() incorrectly uses damos_nth_filter() which
iterates core_filters. As a result, performing a commit unintentionally
corrupts ops_filters.

Add damos_nth_ops_filter() which iterates ops_filters. Use this function
to fix issues caused by wrong iteration.

Fixes: 3607cc590f18 ("mm/damon/core: support committing ops_filters") # 6.15.x
Cc: stable@vger.kernel.org
Signed-off-by: Sang-Heon Jeon <ekffu200098@gmail.com>
---
 mm/damon/core.c | 14 +++++++++++++-
 1 file changed, 13 insertions(+), 1 deletion(-)

diff --git a/mm/damon/core.c b/mm/damon/core.c
index 883d791a10e5..19c8f01fc81a 100644
--- a/mm/damon/core.c
+++ b/mm/damon/core.c
@@ -862,6 +862,18 @@ static struct damos_filter *damos_nth_filter(int n, struct damos *s)
 	return NULL;
 }
 
+static struct damos_filter *damos_nth_ops_filter(int n, struct damos *s)
+{
+	struct damos_filter *filter;
+	int i = 0;
+
+	damos_for_each_ops_filter(filter, s) {
+		if (i++ == n)
+			return filter;
+	}
+	return NULL;
+}
+
 static void damos_commit_filter_arg(
 		struct damos_filter *dst, struct damos_filter *src)
 {
@@ -925,7 +937,7 @@ static int damos_commit_ops_filters(struct damos *dst, struct damos *src)
 	int i = 0, j = 0;
 
 	damos_for_each_ops_filter_safe(dst_filter, next, dst) {
-		src_filter = damos_nth_filter(i++, src);
+		src_filter = damos_nth_ops_filter(i++, src);
 		if (src_filter)
 			damos_commit_filter(dst_filter, src_filter);
 		else
-- 
2.43.0



^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [PATCH v3] mm/damon/core: fix commit_ops_filters by using correct nth function
  2025-08-10 12:42 [PATCH v3] mm/damon/core: fix commit_ops_filters by using correct nth function Sang-Heon Jeon
@ 2025-08-10 12:56 ` Sang-Heon Jeon
  2025-08-10 16:37 ` SeongJae Park
  1 sibling, 0 replies; 3+ messages in thread
From: Sang-Heon Jeon @ 2025-08-10 12:56 UTC (permalink / raw)
  To: sj, honggyu.kim; +Cc: damon, linux-mm, stable

On Sun, Aug 10, 2025 at 9:42 PM Sang-Heon Jeon <ekffu200098@gmail.com> wrote:
>
> damos_commit_ops_filters() incorrectly uses damos_nth_filter() which
> iterates core_filters. As a result, performing a commit unintentionally
> corrupts ops_filters.
>
> Add damos_nth_ops_filter() which iterates ops_filters. Use this function
> to fix issues caused by wrong iteration.
>
> Fixes: 3607cc590f18 ("mm/damon/core: support committing ops_filters") # 6.15.x
> Cc: stable@vger.kernel.org
> Signed-off-by: Sang-Heon Jeon <ekffu200098@gmail.com>
> ---

I just forgot to add change logs.

Changes from v1 [1]:
1. Fix code and commit message style.
2. Merge patch set into one patch.
3. Add fixes and cc section for backporting.

Changes from v2 [2]:
1. Separate the patch into two parts(code modifications and tests) And
this is part of code

[1] https://lore.kernel.org/damon/20250808195518.563053-1-ekffu200098@gmail.com/
[2] https://lore.kernel.org/damon/20250809130756.637304-1-ekffu200098@gmail.com/

>  mm/damon/core.c | 14 +++++++++++++-
>  1 file changed, 13 insertions(+), 1 deletion(-)
>
> diff --git a/mm/damon/core.c b/mm/damon/core.c
> index 883d791a10e5..19c8f01fc81a 100644
> --- a/mm/damon/core.c
> +++ b/mm/damon/core.c
> @@ -862,6 +862,18 @@ static struct damos_filter *damos_nth_filter(int n, struct damos *s)
>         return NULL;
>  }
>
> +static struct damos_filter *damos_nth_ops_filter(int n, struct damos *s)
> +{
> +       struct damos_filter *filter;
> +       int i = 0;
> +
> +       damos_for_each_ops_filter(filter, s) {
> +               if (i++ == n)
> +                       return filter;
> +       }
> +       return NULL;
> +}
> +
>  static void damos_commit_filter_arg(
>                 struct damos_filter *dst, struct damos_filter *src)
>  {
> @@ -925,7 +937,7 @@ static int damos_commit_ops_filters(struct damos *dst, struct damos *src)
>         int i = 0, j = 0;
>
>         damos_for_each_ops_filter_safe(dst_filter, next, dst) {
> -               src_filter = damos_nth_filter(i++, src);
> +               src_filter = damos_nth_ops_filter(i++, src);
>                 if (src_filter)
>                         damos_commit_filter(dst_filter, src_filter);
>                 else
> --
> 2.43.0
>


^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH v3] mm/damon/core: fix commit_ops_filters by using correct nth function
  2025-08-10 12:42 [PATCH v3] mm/damon/core: fix commit_ops_filters by using correct nth function Sang-Heon Jeon
  2025-08-10 12:56 ` Sang-Heon Jeon
@ 2025-08-10 16:37 ` SeongJae Park
  1 sibling, 0 replies; 3+ messages in thread
From: SeongJae Park @ 2025-08-10 16:37 UTC (permalink / raw)
  To: Sang-Heon Jeon
  Cc: SeongJae Park, honggyu.kim, damon, linux-mm, stable,
	Andrew Morton

+ Andrew

On Sun, 10 Aug 2025 21:42:01 +0900 Sang-Heon Jeon <ekffu200098@gmail.com> wrote:

> damos_commit_ops_filters() incorrectly uses damos_nth_filter() which
> iterates core_filters. As a result, performing a commit unintentionally
> corrupts ops_filters.
> 
> Add damos_nth_ops_filter() which iterates ops_filters. Use this function
> to fix issues caused by wrong iteration.
> 
> Fixes: 3607cc590f18 ("mm/damon/core: support committing ops_filters") # 6.15.x
> Cc: stable@vger.kernel.org
> Signed-off-by: Sang-Heon Jeon <ekffu200098@gmail.com>

Reviewed-by: SeongJae Park <sj@kernel.org>


Thanks,
SJ

[...]


^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2025-08-10 16:37 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-08-10 12:42 [PATCH v3] mm/damon/core: fix commit_ops_filters by using correct nth function Sang-Heon Jeon
2025-08-10 12:56 ` Sang-Heon Jeon
2025-08-10 16:37 ` SeongJae Park

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).