[RFC PATCH 7/9] mm/damon/core: set damos_filter default allowance behavior based on installed filters

SeongJae Park posted 9 patches 9 months, 4 weeks ago
There is a newer version of this series
[RFC PATCH 7/9] mm/damon/core: set damos_filter default allowance behavior based on installed filters
Posted by SeongJae Park 9 months, 4 weeks ago
Decide whether to allow or reject by default on core and opertions layer
handled filters evaluation stages, based on the last-installed filter's
behavior.  It is the opposite of the last installed filter's behavior.
If there is any operations layer handled filters, core layer handled
filters stage keeps allowing as the default behavior, since the last
filter of core layer handled filters in the case is not really the last
filter of the entire filtering stage.

Signed-off-by: SeongJae Park <sj@kernel.org>
---
 mm/damon/core.c | 31 +++++++++++++++++++++++++++++--
 1 file changed, 29 insertions(+), 2 deletions(-)

diff --git a/mm/damon/core.c b/mm/damon/core.c
index 78126a5145fd..9744ab9ca5c5 100644
--- a/mm/damon/core.c
+++ b/mm/damon/core.c
@@ -864,6 +864,29 @@ static int damos_commit_ops_filters(struct damos *dst, struct damos *src)
 	return 0;
 }
 
+/**
+ * damos_filters_default_reject() - decide whether to reject memory that didn't
+ *				    match with any given filter.
+ * @filters:	Given DAMOS filters of a group.
+ */
+static bool damos_filters_default_reject(struct list_head *filters)
+{
+	struct damos_filter *last_filter;
+
+	if (list_empty(filters))
+		return false;
+	last_filter = list_last_entry(filters, struct damos_filter, list);
+	return last_filter->allow;
+}
+
+static void damos_set_filters_default_reject(struct damos *s)
+{
+	s->core_filters_default_reject =
+		damos_filters_default_reject(&s->filters);
+	s->ops_filters_default_reject =
+		damos_filters_default_reject(&s->ops_filters);
+}
+
 static int damos_commit_filters(struct damos *dst, struct damos *src)
 {
 	int err;
@@ -871,7 +894,11 @@ static int damos_commit_filters(struct damos *dst, struct damos *src)
 	err = damos_commit_core_filters(dst, src);
 	if (err)
 		return err;
-	return damos_commit_ops_filters(dst, src);
+	err = damos_commit_ops_filters(dst, src);
+	if (err)
+		return err;
+	damos_set_filters_default_reject(dst);
+	return 0;
 }
 
 static struct damos *damon_nth_scheme(int n, struct damon_ctx *ctx)
@@ -1490,7 +1517,7 @@ static bool damos_filter_out(struct damon_ctx *ctx, struct damon_target *t,
 		if (damos_filter_match(ctx, t, r, filter))
 			return !filter->allow;
 	}
-	return false;
+	return s->core_filters_default_reject;
 }
 
 /*
-- 
2.39.5
Re: [RFC PATCH 7/9] mm/damon/core: set damos_filter default allowance behavior based on installed filters
Posted by SeongJae Park 9 months, 3 weeks ago
On Thu, 20 Feb 2025 11:35:07 -0800 SeongJae Park <sj@kernel.org> wrote:

> Decide whether to allow or reject by default on core and opertions layer
> handled filters evaluation stages, based on the last-installed filter's
> behavior.  It is the opposite of the last installed filter's behavior.
> If there is any operations layer handled filters, core layer handled
> filters stage keeps allowing as the default behavior, since the last
> filter of core layer handled filters in the case is not really the last
> filter of the entire filtering stage.

The last sentence describing behavior is not really implemented with this
commit.  See below.

> 
> Signed-off-by: SeongJae Park <sj@kernel.org>
> ---
>  mm/damon/core.c | 31 +++++++++++++++++++++++++++++--
>  1 file changed, 29 insertions(+), 2 deletions(-)
> 
> diff --git a/mm/damon/core.c b/mm/damon/core.c
> index 78126a5145fd..9744ab9ca5c5 100644
> --- a/mm/damon/core.c
> +++ b/mm/damon/core.c
> @@ -864,6 +864,29 @@ static int damos_commit_ops_filters(struct damos *dst, struct damos *src)
>  	return 0;
>  }
>  
> +/**
> + * damos_filters_default_reject() - decide whether to reject memory that didn't
> + *				    match with any given filter.
> + * @filters:	Given DAMOS filters of a group.
> + */
> +static bool damos_filters_default_reject(struct list_head *filters)
> +{
> +	struct damos_filter *last_filter;
> +
> +	if (list_empty(filters))
> +		return false;
> +	last_filter = list_last_entry(filters, struct damos_filter, list);
> +	return last_filter->allow;
> +}
> +
> +static void damos_set_filters_default_reject(struct damos *s)
> +{
> +	s->core_filters_default_reject =
> +		damos_filters_default_reject(&s->filters);
> +	s->ops_filters_default_reject =
> +		damos_filters_default_reject(&s->ops_filters);
> +}

->core_filters_default_reject should be 'false' if s->ops_filters is not empty,
since the last one of ->ops_filters is not the real last filter.  But this code
is not handling the case.

I will fix this in the next revision.


Thanks,
SJ

[...]