Skip to content

Commit

Permalink
mm/damon/sysfs-schemes: return error when for attempts to install fil…
Browse files Browse the repository at this point in the history
…ters on wrong sysfs directory

Return error if the user tries to install a DAMOS filter on DAMOS filters
sysfs directory that assumed to be used for filters that handled by a
DAMON layer that not same to that for the installing filter.

Link: https://lkml.kernel.org/r/20250305222733.59089-7-sj@kernel.org
Signed-off-by: SeongJae Park <sj@kernel.org>
Cc: Jonathan Corbet <corbet@lwn.net>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
  • Loading branch information
SeongJae Park authored and Andrew Morton committed Mar 18, 2025
1 parent 9f643a9 commit ae8fd5b
Showing 1 changed file with 20 additions and 0 deletions.
20 changes: 20 additions & 0 deletions mm/damon/sysfs-schemes.c
Original file line number Diff line number Diff line change
@@ -362,6 +362,23 @@ static ssize_t type_show(struct kobject *kobj,
damon_sysfs_scheme_filter_type_strs[filter->type]);
}

static bool damos_sysfs_scheme_filter_valid_type(
enum damos_sysfs_filter_handle_layer layer,
enum damos_filter_type type)
{
switch (layer) {
case DAMOS_SYSFS_FILTER_HANDLE_LAYER_BOTH:
return true;
case DAMOS_SYSFS_FILTER_HANDLE_LAYER_CORE:
return !damos_filter_for_ops(type);
case DAMOS_SYSFS_FILTER_HANDLE_LAYER_OPS:
return damos_filter_for_ops(type);
default:
break;
}
return false;
}

static ssize_t type_store(struct kobject *kobj,
struct kobj_attribute *attr, const char *buf, size_t count)
{
@@ -373,6 +390,9 @@ static ssize_t type_store(struct kobject *kobj,
for (type = 0; type < NR_DAMOS_FILTER_TYPES; type++) {
if (sysfs_streq(buf, damon_sysfs_scheme_filter_type_strs[
type])) {
if (!damos_sysfs_scheme_filter_valid_type(
filter->handle_layer, type))
break;
filter->type = type;
ret = count;
break;

0 comments on commit ae8fd5b

Please sign in to comment.