stable.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH 0/6] mm/damon: fix misc bugs in DAMON modules
@ 2025-07-06 19:32 SeongJae Park
  2025-07-06 19:32 ` [PATCH 1/6] samples/damon/wsse: fix boot time enable handling SeongJae Park
  2025-07-06 19:32 ` [PATCH 3/6] samples/damon/mtier: support boot time enable setup SeongJae Park
  0 siblings, 2 replies; 3+ messages in thread
From: SeongJae Park @ 2025-07-06 19:32 UTC (permalink / raw)
  To: Andrew Morton
  Cc: SeongJae Park, damon, kernel-team, linux-kernel, linux-mm, stable

From manual code review, I found below bugs in DAMON modules.

DAMON sample modules crash if those are enabled at boot time, via kernel
command line.  A similar issue was found and fixed on DAMON non-sample
modules in the past, but we didn't check that for sample modules.

DAMON non-sample modules are not setting 'enabled' parameters
accordingly when real enabling is failed.  Honggyu found and fixed[1]
this type of bugs in DAMON sample modules, and my inspection was
motivated by the great work.  Kudos to Honggyu.

Finally, DAMON_RECLIAM is mistakenly losing scheme internal status due
to misuse of damon_commit_ctx().  DAMON_LRU_SORT has a similar misuse,
but fortunately it is not causing real status loss.

Fix the bugs.  Since these are similar patterns of bugs that were found
in the past, it would be better to add tests or refactor the code, in
future.

Note that the fix of the second bug for DAMON_STAT is sent
separately[2], since it is a fix for a bug in mm-unstable tree at the
moment.  Also as mentioned above, DAMON_LRU_SORT also has a misuse of
damon_commit_ctx(), but it is not causing a real issue, hence the fix is
not included in this series.  I will post it later.

[1] https://lore.kernel.org/20250702000205.1921-1-honggyu.kim@sk.com
[2] https://lore.kernel.org/20250706184750.36588-1-sj@kernel.org

SeongJae Park (6):
  samples/damon/wsse: fix boot time enable handling
  samples/damon/prcl: fix boot time enable crash
  samples/damon/mtier: support boot time enable setup
  mm/damon/reclaim: reset enabled when DAMON start failed
  mm/damon/lru_sort: reset enabled when DAMON start failed
  mm/damon/reclaim: use parameter context correctly

 mm/damon/lru_sort.c   |  5 ++++-
 mm/damon/reclaim.c    |  9 ++++++---
 samples/damon/mtier.c | 13 +++++++++++++
 samples/damon/prcl.c  | 13 +++++++++++++
 samples/damon/wsse.c  | 15 ++++++++++++++-
 5 files changed, 50 insertions(+), 5 deletions(-)


base-commit: a555ad24c884e9f4ee2f2a0184f5b7b89c8d4a6e
-- 
2.39.5

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

* [PATCH 1/6] samples/damon/wsse: fix boot time enable handling
  2025-07-06 19:32 [PATCH 0/6] mm/damon: fix misc bugs in DAMON modules SeongJae Park
@ 2025-07-06 19:32 ` SeongJae Park
  2025-07-06 19:32 ` [PATCH 3/6] samples/damon/mtier: support boot time enable setup SeongJae Park
  1 sibling, 0 replies; 3+ messages in thread
From: SeongJae Park @ 2025-07-06 19:32 UTC (permalink / raw)
  To: Andrew Morton
  Cc: SeongJae Park, damon, kernel-team, linux-kernel, linux-mm, stable

If 'enable' parameter of the 'wsse' DAMON sample module is set at boot
time via the kernel command line, memory allocation is tried before the
slab is initialized.  As a result kernel NULL pointer dereference BUG
can happen.  Fix it by checking the initialization status.

Fixes: b757c6cfc696 ("samples/damon/wsse: start and stop DAMON as the user requests")
Cc: stable@vger.kernel.org
Signed-off-by: SeongJae Park <sj@kernel.org>
---
 samples/damon/wsse.c | 15 ++++++++++++++-
 1 file changed, 14 insertions(+), 1 deletion(-)

diff --git a/samples/damon/wsse.c b/samples/damon/wsse.c
index e20238a249e7..15e2683fe5f3 100644
--- a/samples/damon/wsse.c
+++ b/samples/damon/wsse.c
@@ -89,6 +89,8 @@ static void damon_sample_wsse_stop(void)
 		put_pid(target_pidp);
 }
 
+static bool init_called;
+
 static int damon_sample_wsse_enable_store(
 		const char *val, const struct kernel_param *kp)
 {
@@ -103,6 +105,9 @@ static int damon_sample_wsse_enable_store(
 		return 0;
 
 	if (enable) {
+		if (!init_called)
+			return 0;
+
 		err = damon_sample_wsse_start();
 		if (err)
 			enable = false;
@@ -114,7 +119,15 @@ static int damon_sample_wsse_enable_store(
 
 static int __init damon_sample_wsse_init(void)
 {
-	return 0;
+	int err = 0;
+
+	init_called = true;
+	if (enable) {
+		err = damon_sample_wsse_start();
+		if (err)
+			enable = false;
+	}
+	return err;
 }
 
 module_init(damon_sample_wsse_init);
-- 
2.39.5

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

* [PATCH 3/6] samples/damon/mtier: support boot time enable setup
  2025-07-06 19:32 [PATCH 0/6] mm/damon: fix misc bugs in DAMON modules SeongJae Park
  2025-07-06 19:32 ` [PATCH 1/6] samples/damon/wsse: fix boot time enable handling SeongJae Park
@ 2025-07-06 19:32 ` SeongJae Park
  1 sibling, 0 replies; 3+ messages in thread
From: SeongJae Park @ 2025-07-06 19:32 UTC (permalink / raw)
  To: Andrew Morton
  Cc: SeongJae Park, damon, kernel-team, linux-kernel, linux-mm, stable

If 'enable' parameter of the 'mtier' DAMON sample module is set at boot
time via the kernel command line, memory allocation is tried before the
slab is initialized.  As a result kernel NULL pointer dereference BUG
can happen.  Fix it by checking the initialization status.

Fixes: 82a08bde3cf7 ("samples/damon: implement a DAMON module for memory tiering")
Cc: stable@vger.kernel.org
Signed-off-by: SeongJae Park <sj@kernel.org>
---
 samples/damon/mtier.c | 13 +++++++++++++
 1 file changed, 13 insertions(+)

diff --git a/samples/damon/mtier.c b/samples/damon/mtier.c
index 97892ade7f31..20c3102242ec 100644
--- a/samples/damon/mtier.c
+++ b/samples/damon/mtier.c
@@ -157,6 +157,8 @@ static void damon_sample_mtier_stop(void)
 	damon_destroy_ctx(ctxs[1]);
 }
 
+static bool init_called;
+
 static int damon_sample_mtier_enable_store(
 		const char *val, const struct kernel_param *kp)
 {
@@ -170,6 +172,9 @@ static int damon_sample_mtier_enable_store(
 	if (enable == enabled)
 		return 0;
 
+	if (!init_called)
+		return 0;
+
 	if (enable) {
 		err = damon_sample_mtier_start();
 		if (err)
@@ -182,6 +187,14 @@ static int damon_sample_mtier_enable_store(
 
 static int __init damon_sample_mtier_init(void)
 {
+	int err = 0;
+
+	init_called = true;
+	if (enable) {
+		err = damon_sample_mtier_start();
+		if (err)
+			enable = false;
+	}
 	return 0;
 }
 
-- 
2.39.5

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

end of thread, other threads:[~2025-07-06 19:32 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-07-06 19:32 [PATCH 0/6] mm/damon: fix misc bugs in DAMON modules SeongJae Park
2025-07-06 19:32 ` [PATCH 1/6] samples/damon/wsse: fix boot time enable handling SeongJae Park
2025-07-06 19:32 ` [PATCH 3/6] samples/damon/mtier: support boot time enable setup 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).