]> git.ipfire.org Git - thirdparty/kernel/stable-queue.git/blob
9cdfb9ab1e6094ae6b335d93c8a6967b0b5f8cbf
[thirdparty/kernel/stable-queue.git] /
1 From 95bc35f9bee5220dad4e8567654ab3288a181639 Mon Sep 17 00:00:00 2001
2 From: SeongJae Park <sj@kernel.org>
3 Date: Tue, 22 Nov 2022 19:48:31 +0000
4 Subject: mm/damon/sysfs: fix wrong empty schemes assumption under online tuning in damon_sysfs_set_schemes()
5
6 From: SeongJae Park <sj@kernel.org>
7
8 commit 95bc35f9bee5220dad4e8567654ab3288a181639 upstream.
9
10 Commit da87878010e5 ("mm/damon/sysfs: support online inputs update") made
11 'damon_sysfs_set_schemes()' to be called for running DAMON context, which
12 could have schemes. In the case, DAMON sysfs interface is supposed to
13 update, remove, or add schemes to reflect the sysfs files. However, the
14 code is assuming the DAMON context wouldn't have schemes at all, and
15 therefore creates and adds new schemes. As a result, the code doesn't
16 work as intended for online schemes tuning and could have more than
17 expected memory footprint. The schemes are all in the DAMON context, so
18 it doesn't leak the memory, though.
19
20 Remove the wrong asssumption (the DAMON context wouldn't have schemes) in
21 'damon_sysfs_set_schemes()' to fix the bug.
22
23 Link: https://lkml.kernel.org/r/20221122194831.3472-1-sj@kernel.org
24 Fixes: da87878010e5 ("mm/damon/sysfs: support online inputs update")
25 Signed-off-by: SeongJae Park <sj@kernel.org>
26 Cc: <stable@vger.kernel.org> [5.19+]
27 Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
28 Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
29 ---
30 mm/damon/sysfs.c | 46 ++++++++++++++++++++++++++++++++++++++++++++--
31 1 file changed, 44 insertions(+), 2 deletions(-)
32
33 --- a/mm/damon/sysfs.c
34 +++ b/mm/damon/sysfs.c
35 @@ -2286,12 +2286,54 @@ static struct damos *damon_sysfs_mk_sche
36 sysfs_scheme->action, &quota, &wmarks);
37 }
38
39 +static void damon_sysfs_update_scheme(struct damos *scheme,
40 + struct damon_sysfs_scheme *sysfs_scheme)
41 +{
42 + struct damon_sysfs_access_pattern *access_pattern =
43 + sysfs_scheme->access_pattern;
44 + struct damon_sysfs_quotas *sysfs_quotas = sysfs_scheme->quotas;
45 + struct damon_sysfs_weights *sysfs_weights = sysfs_quotas->weights;
46 + struct damon_sysfs_watermarks *sysfs_wmarks = sysfs_scheme->watermarks;
47 +
48 + scheme->pattern.min_sz_region = access_pattern->sz->min;
49 + scheme->pattern.max_sz_region = access_pattern->sz->max;
50 + scheme->pattern.min_nr_accesses = access_pattern->nr_accesses->min;
51 + scheme->pattern.max_nr_accesses = access_pattern->nr_accesses->max;
52 + scheme->pattern.min_age_region = access_pattern->age->min;
53 + scheme->pattern.max_age_region = access_pattern->age->max;
54 +
55 + scheme->action = sysfs_scheme->action;
56 +
57 + scheme->quota.ms = sysfs_quotas->ms;
58 + scheme->quota.sz = sysfs_quotas->sz;
59 + scheme->quota.reset_interval = sysfs_quotas->reset_interval_ms;
60 + scheme->quota.weight_sz = sysfs_weights->sz;
61 + scheme->quota.weight_nr_accesses = sysfs_weights->nr_accesses;
62 + scheme->quota.weight_age = sysfs_weights->age;
63 +
64 + scheme->wmarks.metric = sysfs_wmarks->metric;
65 + scheme->wmarks.interval = sysfs_wmarks->interval_us;
66 + scheme->wmarks.high = sysfs_wmarks->high;
67 + scheme->wmarks.mid = sysfs_wmarks->mid;
68 + scheme->wmarks.low = sysfs_wmarks->low;
69 +}
70 +
71 static int damon_sysfs_set_schemes(struct damon_ctx *ctx,
72 struct damon_sysfs_schemes *sysfs_schemes)
73 {
74 - int i;
75 + struct damos *scheme, *next;
76 + int i = 0;
77 +
78 + damon_for_each_scheme_safe(scheme, next, ctx) {
79 + if (i < sysfs_schemes->nr)
80 + damon_sysfs_update_scheme(scheme,
81 + sysfs_schemes->schemes_arr[i]);
82 + else
83 + damon_destroy_scheme(scheme);
84 + i++;
85 + }
86
87 - for (i = 0; i < sysfs_schemes->nr; i++) {
88 + for (; i < sysfs_schemes->nr; i++) {
89 struct damos *scheme, *next;
90
91 scheme = damon_sysfs_mk_scheme(sysfs_schemes->schemes_arr[i]);