Skip to content

Commit ae8fd5b

Browse files
sjp38akpm00
authored andcommitted
mm/damon/sysfs-schemes: return error when for attempts to install filters 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>
1 parent 9f643a9 commit ae8fd5b

File tree

1 file changed

+20
-0
lines changed

1 file changed

+20
-0
lines changed

mm/damon/sysfs-schemes.c

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -362,6 +362,23 @@ static ssize_t type_show(struct kobject *kobj,
362362
damon_sysfs_scheme_filter_type_strs[filter->type]);
363363
}
364364

365+
static bool damos_sysfs_scheme_filter_valid_type(
366+
enum damos_sysfs_filter_handle_layer layer,
367+
enum damos_filter_type type)
368+
{
369+
switch (layer) {
370+
case DAMOS_SYSFS_FILTER_HANDLE_LAYER_BOTH:
371+
return true;
372+
case DAMOS_SYSFS_FILTER_HANDLE_LAYER_CORE:
373+
return !damos_filter_for_ops(type);
374+
case DAMOS_SYSFS_FILTER_HANDLE_LAYER_OPS:
375+
return damos_filter_for_ops(type);
376+
default:
377+
break;
378+
}
379+
return false;
380+
}
381+
365382
static ssize_t type_store(struct kobject *kobj,
366383
struct kobj_attribute *attr, const char *buf, size_t count)
367384
{
@@ -373,6 +390,9 @@ static ssize_t type_store(struct kobject *kobj,
373390
for (type = 0; type < NR_DAMOS_FILTER_TYPES; type++) {
374391
if (sysfs_streq(buf, damon_sysfs_scheme_filter_type_strs[
375392
type])) {
393+
if (!damos_sysfs_scheme_filter_valid_type(
394+
filter->handle_layer, type))
395+
break;
376396
filter->type = type;
377397
ret = count;
378398
break;

0 commit comments

Comments
 (0)